Consuming SOAP WS in GoLang

6,135 views
Skip to first unread message

mustafizu...@gmail.com

unread,
Jun 25, 2015, 10:28:29 AM6/25/15
to golan...@googlegroups.com
Hello, 
 I am trying to consume a SOAP web-service using GoLang. I am sending a sample request and expected response
below. Kindly note that the text in bold-and-italics in the Request are user inputs and in the Response is the expected
response (contents of file in hex).

SOAP Request:
POST /service1.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
 <soap12:Body>
<getFile xmlns="http://tempuri.org/">
 <userName>dynamicString</userName> //user input
 <passWord>dynamicString</passWord> //user input
  <FileName>dynamicString</FileName> //user input
</getFile>
 </soap12:Body>
</soap12:Envelope>


SOAP Response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
 <soap12:Body>
<getFileResponse xmlns="http://tempuri.org/">
 <getFileResult>fileContentsinHexFormat</getFileResult> //file contents in hex format
</getFileResponse>
 </soap12:Body>
</soap12:Envelope>

 I could not find any GoLang libraries to do it automatically. I could communicate with the server, but due to some error in 
formatting the request, the server always sends a 500 error status code. The main problem is to insert the user inputs in
the request (in correct format). Can someone kindly help me out with a nice way of forming the SOAP request? Code 
snippets will be very helpful. Thank you for your time and efforts.

Cheers!

Mustafizur

Matt Harden

unread,
Jun 25, 2015, 11:38:27 AM6/25/15
to mustafizu...@gmail.com, golan...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Lowther

unread,
Jun 27, 2015, 4:38:57 PM6/27/15
to golan...@googlegroups.com
Shameless self promotion: https://github.com/VictorLowther/soap

Sean Russell

unread,
Jun 29, 2015, 7:48:27 AM6/29/15
to golan...@googlegroups.com, mustafizu...@gmail.com
Hi,

On Thursday, June 25, 2015 at 10:28:29 AM UTC-4, mustafizu...@gmail.com wrote:
I am trying to consume a SOAP web-service using GoLang. I am sending a sample request and expected response
below. Kindly note that the text in bold-and-italics in the Request are user inputs and in the Response is the expected
response (contents of file in hex).

I've had some limited success with gowsdl (if you have access to the WSDL definition of the service). SOAP 2.0 isn't supported.  This may be the underlying reason for all of the other problems (below) that I encountered with it:
  • the output is pretty ugly -- lots of spurious white space
  • the generated code doesn't compile, and needs quite a bit of repair
  • after clean-up, a fair bit of tweaking is necessary to get it to function properly
  • it doesn't do a very good job at normalizing the resulting code (lots of duplicate code for identical signature structures)
Sadly, this means it isn't suitable for go generate, but it is still a godsend when dealing with a large API -- fixing the output of gowsdl is still easier than writing all that boilerplate, and the underlying SOAP operations are handy.  Many thanks and a shout out to hooklift for providing it!  I forked it here because I needed to pass in additional HTTP request headers, and this functionality was commented out in the upstream package for some reason.  I hope as time goes on the need to deal with SOAP increasingly diminishes, and I'm not planning on other changes to my fork, so I recommend sticking with the upstream version unless you need the header functionality.  Upstream hasn't changed since I forked it, but while there isn't a lot of activity, it doesn't look dead.

I had also tried go-soap; it generates a single, mostly empty project file.  Maybe because of SOAP 2 incompatibility as well, but I didn't dig into it.  It lacks even a rudimentary help function, so I assumed it was too immature to try fixing.  It certainly didn't get as far as gowsdl.

Good luck, and my deepest condolences that you, too, have to deal with SOAP.

--- SER
Reply all
Reply to author
Forward
0 new messages