Code Monkey home page Code Monkey logo

soap's Introduction

SOAP is dead - long live SOAP

First of all do not write SOAP services if you can avoid it! It is over.

If you can not avoid it this package might help.

Service

package main

import (
	"encoding/xml"
	"fmt"
	"net/http"

	"github.com/foomo/soap"
)

// FooRequest a simple request
type FooRequest struct {
	XMLName xml.Name `xml:"fooRequest"`
	Foo     string
}

// FooResponse a simple response
type FooResponse struct {
	Bar string
}

// RunServer run a little demo server
func RunServer() {
	soapServer := soap.NewServer()
	soapServer.HandleOperation(
		// SOAPAction
		"operationFoo",
		// tagname of soap body content
		"fooRequest",
		// RequestFactoryFunc - give the server sth. to unmarshal the request into
		func() interface{} {
			return &FooRequest{}
		},
		// OperationHandlerFunc - do something
		func(request interface{}, w http.ResponseWriter, httpRequest *http.Request) (response interface{}, err error) {
			fooRequest := request.(*FooRequest)
			fooResponse := &FooResponse{
				Bar: "Hello " + fooRequest.Foo,
			}
			response = fooResponse
			return
		},
	)
	err := soapServer.ListenAndServe(":8080")
	fmt.Println("exiting with error", err)
}

func main() {
	RunServer()
}

Client

package main

import (
	"encoding/xml"
	"log"

	"github.com/foomo/soap"
)

// FooRequest a simple request
type FooRequest struct {
	XMLName xml.Name `xml:"fooRequest"`
	Foo     string
}

// FooResponse a simple response
type FooResponse struct {
	Bar string
}

func main() {
	soap.Verbose = true
	client := soap.NewClient("http://127.0.0.1:8080/", nil, nil)
	response := &FooResponse{}
	httpResponse, err := client.Call("operationFoo", &FooRequest{Foo: "hello i am foo"}, response)
	if err != nil {
		panic(err)
	}
	log.Println(response.Bar, httpResponse.Status)
}

soap's People

Contributors

florianschlegel avatar janhalfar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

soap's Issues

build envelope with soapenv

my webservice server must use a envelope like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
how can I get it ?

the xmlns:soapenv can't set in XMLNAME

sorry. use attr can do this

Client.Call() check for "<soap" or "<SOAP" tag invalidates XML body

First off I'd like to say a big thank you to the makers of this package, your work has helped save my a lot of time in setting up my soap server and client.

However when using the client, to make a call (i.e. client.Call(...)) I get a This is not a SOAP-Message error even when sending valid XML envelopes. I did some digging around and I found this line of code below in the client.go file:

if !(strings.Contains(string(rawbody), "<soap") || strings.Contains(string(rawbody), "<SOAP")) {
			l("This is not a SOAP-Message: \n" + string(rawbody))
			return nil, errors.New("This is not a SOAP-Message: \n" + string(rawbody))
		}

This checks to see if the incoming SOAP envelope has either a "<soap"or "<SOAP" tag anywhere in the response envelope.
I'd like to know first of all why this is important to check for, as some of SOAP envelopes do not contain a soap prefix at all, as see in this example below:

<?xml version="1.0" encoding="UTF-8" ?>
 <NESingleResponse>
<SessionID>000001100913103301000000000001</SessionID> <DestinationInstitutionCode>000002</DestinationInstitutionCode> 
<ChannelCode>1</ChannelCode> 
<AccountNumber>2222000000012345</AccountNumber> 
<AccountName>Ajibade Oluwasegun</AccountName> 
<BankVerificationNumber>1033000441</BankVerificationNumber> 
<KYCLevel>1</KYCLevel>
<ResponseCode>00</ResponseCode>
 </NESingleResponse>

And also can this be removed? so that Envelopes as given in the example below can be parsed as well.

Thank you very much

Please add a license

Without a license, your code is under default copyright laws per github's T&Cs, which are extremely restrictive.

Getting error for multipart SOAP request

2022/09/08 23:06:03 handling error: could not probe soap body content:: XML syntax error on line 4: invalid XML name: 0.urn:uuid:27DFFC077EEECBFBEE1662658563684
2022/09/08 23:06:03 writing response:




could not probe soap body content:: XML syntax error on line 4: invalid XML name: 0.urn:uuid:27DFFC077EEECBFBEE1662658563684


handling error: unknown path

The example server finally run after I change HandleOperation to RegisterHandler and add '"xml",' under '"fooRequest",'. But I always get the error when I run the client.go. What the problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.