Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Savon with SOAP


  • Please log in to reply
2 replies to this topic

#1 tyger86

tyger86

    Passenger

  • Members
  • 2 posts

Posted 15 August 2013 - 07:03 PM

Hey all I hope someone out there is a savon 2 guru because I a stuck. In savon's documentation it never assumes one might want to have multiple top level tags in the body however the service I am using does. I need something like

 

<soap:Body>
  <extLoginData>
    <ThreePLKey>xxx</ThreePLKey>
    <FacilityID>xxx</FacilityID>
   </extLoginData>
    <orders xmlns="http://www.joi.com/schemas/ViaSub.WMS/">
      <Order>
        <name>Stuff</name>
      </Order>
    </orders>
</soap:Body>

 

But what I am getting with savon is

 

<soap:Body>
  <extLoginData>
      <extLoginData>
        <ThreePLKey>xxx</ThreePLKey>
        <FacilityID>xxx</FacilityID>
      </extLoginData>
      <orders xmlns="http://www.joi.com/schemas/ViaSub.WMS/">
        <Order>
          <name>Stuff</name>
        </Order>
      </orders>
     </extLoginData>
</soap:Body>
 

 

The server is responding with an error saying orders can't be empty and that's because its embeded in the extLoginData tag. My savon code looks like

 

 
message = {
  "extLoginData" => {
    "ThreePLKey" => api_key,
    "Login" => "tyrel",
    "Password" => "live",
    "FacilityID" => api_id
  },
  "orders" => { 
    :@xmlns => "http://www.joi.com/schemas/ViaSub.WMS/",
    :content! => {
      "Order" => {
        "TransInfo" => {
          "ReferenceNum" => "F$%^ 3PL ;)",
          "PONum" => "12345",
      },
      "ShipTo" => {
        "Name" => "Bob Migee",
        "Address" => {
        "Address1" => "12345 Fake st.",
        "Address2" => "Unit 34",
        "City" => "Denver",
        "State" => "CA",
        "Zip" => "80021",
        "Country" => "US"
     },
    "PhoneNumber1" => "123-456-7890",
    "EmailAddress1" => "bob@fake_host.net",
    "CustomerName" => "Tyrel Richey"
  },
  "ShippingInstructions" => {
    "Carrier" => "USPS",
    "Mode" => "First Class Male",
    "BillingCode" => "Prepaid",
  },
  "OrderLineItems" => {
    "OrderLineItem" => {
    "SKU" => "LU234",
    "Qualifier" => "XXX",
    "Qty" => 1
    }
  }
 }
}
}
}
 
client.call(
  :create_orders,
  message: message
)
 

 

Its picking up the top level from the wsdl and auto generating it and assuming I want to surround the entire body can I override this.



#2 danbys

danbys

    Passenger

  • Members
  • 1 posts

Posted 17 August 2013 - 08:40 AM

Are you sure namespace for order is correct? Have you debugged and verify that your request use the correct namespace? I use the following syntax when I specify ns.

message = {
  "extLoginData" => {
    "ThreePLKey" => api_key,
    "Login" => "tyrel",
    "Password" => "live",
    "FacilityID" => api_id
  },
  "orders" => { 
      "Order" => {
        "TransInfo" => {
          "ReferenceNum" => "F$%^ 3PL ;)",
          "PONum" => "12345",
      },
      "ShipTo" => {
        "Name" => "Bob Migee",
        "Address" => {
        "Address1" => "12345 Fake st.",
        "Address2" => "Unit 34",
        "City" => "Denver",
        "State" => "CA",
        "Zip" => "80021",
        "Country" => "US"
     },
    "PhoneNumber1" => "123-456-7890",
    "EmailAddress1" => "bob@fake_host.net",
    "CustomerName" => "Tyrel Richey"
    },
    "ShippingInstructions" => {
      "Carrier" => "USPS",
      "Mode" => "First Class Male",
      "BillingCode" => "Prepaid",
    },
    "OrderLineItems" => {
      "OrderLineItem" => {
      "SKU" => "LU234",
      "Qualifier" => "XXX",
      "Qty" => 1
      }
    }
   }
  },
  attributes!: {
    orders: {
      xmlns: 'http://www.joi.com/schemas/ViaSub.WMS/'
    }
  }
}

/Dan



#3 tyger86

tyger86

    Passenger

  • Members
  • 2 posts

Posted 17 August 2013 - 01:27 PM

Hey thanks for the response Dan. The main problem is their server is expecting orders and extLoginData to be at the top level right bellow the body.

<Body>
<extLoginData>

....

</extLoginData>
<orders>
<Order></Order>
</orders>
</Body>

However savon auto generates

<Body>
<extLoginData>
<extLoginData>

....

</extLoginData>
<orders>
<Order></Order>
</orders>
</extLoginData>
</Body>

I was wondering if there is a way to override the auto generation of the top level tag.


Edited by Jamie, 17 August 2013 - 02:09 PM.
Added code tags





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users