1

I'm working with ruby and Savon 2. I have been given the following SOAP example:

POST /WebApi/Services/b2bapi.asmx HTTP/1.1
Host: api.nationsphotolab.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://api.nationsphotolab.com/AddNewOrder"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddNewOrder xmlns="http://api.nationsphotolab.com/">
      <orderXml>string</orderXml>
      <passport>
        <Source>string</Source>
        <Hash>string</Hash>
      </passport>
    </AddNewOrder>
  </soap:Body>
</soap:Envelope>

I have tried a bunch of different methods of creating the XML, first using XmlMarkup builder, and then just building a hash and passing it into the savon client call.

The error I've been getting: Savon::SOAPFault ((soap:Server) Server was unable to process request. ---> Object reference not set to an instance of an object.):

Here's the request:

client = Savon.client(wsdl: "http://api.nationsphotolab.com/WebApi/Services/b2bapi.asmx?wsdl")
response = client.call(:add_new_order, message: data)

With data being an XML created using XmlMarkup builder. Attached is a screenshot of data.

Please let me know if I can provide anymore information

Example data: enter image description here

Thank you!

Syfer
  • 4,262
  • 3
  • 20
  • 37
Bradley T.
  • 11
  • 1
  • 4

1 Answers1

0

From your description it looks like the API is expecting the orderXML element to be a string. I think the problem is that you put XML into the orderXML element, when the API is expecting it to contain a string.

Escaping the contents of the orderXML element and sending it as a string should solve the problem.

The code below shows one way of escaping XML strings: order_xml_string.encode(xml: :text)

corthmann
  • 377
  • 1
  • 2
  • 9
  • Doesn't seem to alleviate the problem. I tried wrapping in cdata tags but I think the main problem is that the whole payload is being passed as a string. How can I pass it as an object with only the orderXML string and passport as params? – Bradley T. Jul 26 '17 at 15:08
  • @BradleyT. can you try to execute the request with `log_level: :debug` (option for the `Savon.client` initialization) ? That will print the request/response and make it easy for you to verify if your code is escaping the whole payload or only the orderXML element as intended. – corthmann Jul 26 '17 at 19:53
  • also. naturally you'd only need to add: `.encode(xml: :text)` to the variable that contains the `orderXML` data – corthmann Jul 26 '17 at 19:56
  • I think that the problem is that the entire payload is currently one big string, when only the order, source, and hash should be strings. When I put a pry in and look at the xml payload that is being passed in, it's one big string including the version, encoding, envelope, body, etc. – Bradley T. Jul 27 '17 at 14:29