0

I am getting the following error when accessing a WSDL SOAP server:

{:error=>true, :message=>"Savon::SOAPFault: (env:Client) JAXRPCTIE01: caught exception while handling request: unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual="}

I went to soapclient.com to figure out what it's looking for.

Here is the error message I'm receiving. Here is the code I'm using to connect to the SOAP client:

  my_hash_of_stuff = {
      zipcode: d_zip,
      country: country
  }

  wsdl = 'http://my.yrc.com/dynamic/national/WebServices/YRCZipFinder_V1.wsdl'

  client = Savon.client(wsdl: wsdl,
                        logger: Rails.logger,
                        log_level: :debug,
                        log: true,
                        pretty_print_xml: true,
                        env_namespace: :'soap-env',
                        strip_namespaces: true

  )


  response = client.call(:lookup_zip, message: my_hash_of_stuff)

  print response.to_hash

Here's a copy of my log output so you can see what's happening.

This appears to be what the SOAP request should look like according to soapclient.com (if i'm understanding it correctly).

This is what I am sending.

I've been fighting with it all day and I'm sure it's probably a combination of my ignorance and something simple that i'm missing. Hopefully you guys might be able to help?

EDIT 05/25/2016: So, looking at this again today, here's the log showing the request that savon is making:

HTTPI GET request to my.yrc.com (net_http)
SOAP request: http://my.yrc.com/dynamic/national/webservice/YRCZipFinder_V1
SOAPAction: "http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl/lookupCity", Content-Type: text/xml;charset=UTF-8, Content-Length: 417
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <tns:lookupCity>
      <zipCode>84101</zipCode>
      <country>USA</country>
    </tns:lookupCity>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here's what a correct one looks like. I got this from the existing php app and tested it in Postman to verify that it works:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://my.yrc.com/national/WebServices/YRCZipFinderMessages_V1.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:lookupCity>
            <lookupCityRequest xsi:type="ns2:YRCLookupCityRequest">
                <zipCode xsi:type="xsd:string">84101</zipCode>
                <country xsi:type="ns2:CountryCode">USA</country>
            </lookupCityRequest>
        </ns1:lookupCity>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

UPDATE:

After some more hacking, I have my request looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.yrc.com/national/WebServices/YRCZipFinder_V1.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://my.yrc.com/national/WebServices/YRCZipFinderMessages_V1.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <tns:lookupCity lookupCityRequest="ns2:YRCLookupCityRequest">
      <zipCode>84101</zipCode>
      <country>USA</country>
    </tns:lookupCity>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I need to get lookupCityRequest to move inside lookupCity instead of being an attribute of lookupCity, however. Testing it in Postman, that appears to be the only stumbling block left to hurdle.

Steffen Roller
  • 3,464
  • 25
  • 43
Jason Shultz
  • 940
  • 1
  • 19
  • 36
  • look on this link...this format may help you.. [stackoverflow.com/questions/28434493](http://stackoverflow.com/questions/28434493/rails-pass-soap-basic-auth-with-savon/31490846#31490846) – Mukesh May 25 '16 at 05:48

1 Answers1

1

You can use the special :attribute!symbol to assign additional attributes. That's a functionality from Nokogiri which Savon uses to build XML.

require 'savon'

my_hash_of_stuff = 
  { zipcode: "99103",
    country: 'US',
    attributes!: { :country => { 'xsi:type' => 'ns2:YRCLookupCityRequest'},
                   :zipcode => { 'xsi:type' => 'ns2:YRCLookupCityRequest' }}
}


wsdl = 'http://my.yrc.com/dynamic/national/WebServices/YRCZipFinder_V1.wsdl'

client = Savon.client(wsdl: wsdl,
                      # logger: Rails.logger,
                      log_level: :debug,
                      log: true,
                      pretty_print_xml: true,
                      env_namespace: :'soap-env',
                      strip_namespaces: true
)

response = client.call(:lookup_zip,
                       message: my_hash_of_stuff)

print response.to_hash

If nothing works and you're desperate enough then you can still create your very own XML and use xml: instead of message:.

Steffen Roller
  • 3,464
  • 25
  • 43
  • Hey, Steffen, what is the attributes key you are referring to? I'm looking at the globals page on the repo but don't see it. I tried your suggestion, but it still fails with `"Savon::SOAPFault: (env:Client) JAXRPCTIE01: caught exception while handling request: unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual="` – Jason Shultz May 25 '16 at 14:06
  • ok, it was a local param, i see. so i just tried that, but it's not placing it where it needs to go. it looks like it needs to go here: `` but instead it's putting it in the body. – Jason Shultz May 25 '16 at 21:17
  • so - did it help, did it not? – Steffen Roller Jun 06 '16 at 14:18
  • no, not really, I ended up writing my own SOAP service to make the queries. I had to do one for each of the services I was connecting to. Sorry. – Jason Shultz Jun 06 '16 at 23:13