2

I'm attempting to build a proper SOAP header:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sen="https://webservices.averittexpress.com/SendWebImageService">
<soapenv:Header
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns:authnHeader
soapenv:mustUnderstand="0"
xmlns:ns="http://webservices.averittexpress.com/authn">
<Username>xxxxxxxx</Username> <Password>xxxxxxxx</Password>
</ns:authnHeader> </soapenv:Header>

This is my Savon client call, I'm using version 2:

client = Savon.client(
  wsdl: api_url,
  raise_errors: false,
  convert_request_keys_to: :camelcase,
  element_form_default: :qualified,
  env_namespace: :soapenv,
  soap_header: {'username' => username, 'password' => password }
)

I'm getting the following SOAP error:

fault=>
  {:faultcode=>"soapenv:Server",
  :faultstring=>"java.lang.NullPointerException",
  :detail=>nil}}

How do I get the sapoenv:mustUserstand="0" line, and what is it?

Plus I'm confused how to set the xmlns:ns="http://webservices.averittexpress.com/authn">.

I've little experience using SOAP requests, and am coming from a Ruby/Rails RESTful background. Any help would be appreciated.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
TheIrishGuy
  • 2,531
  • 19
  • 23

1 Answers1

4

Savon uses Gyoku to convert both SOAP header and body to XML.
Following this libraries conventions, here's what your Hash needs to look like:

soap_header = {
  "ns:authnHeader" => {
    "@soapenv:mustUnderstand" => 0,
    "@xmlns:ns" => "http://webservices.averittexpress.com/authn",
    "Username"  => "x",
    "Password"  => "x"
  }
}

Savon.client(:soap_header => soap_header)
rubiii
  • 6,903
  • 2
  • 38
  • 51
  • Thank you for this. One question, though, i'm still receiving only a {:fault=> {:faultcode=>"soapenv:Server", :faultstring=>"java.lang.NullPointerException"}} error in my response. In your experience, what does this actually mean? lol – TheIrishGuy Jan 15 '13 at 23:41
  • it means the service is missing tests :) a very basic code problem. could be anything. – rubiii Jan 15 '13 at 23:47
  • Thanks again for your help. I had to specify my namespace as "http://schemas.xmlsoap.org/wsdl/" there wsdl file was setting it for some reason. Now i'm getting actual helpful errors. – TheIrishGuy Jan 16 '13 at 00:45