jeudi 8 octobre 2020

Savon::SOAPFault: (s:Client) Element 'RequestContext' is missing from the header

I am using savon gem in rails to call purolator E-Ship soap APIs,

gem 'savon', version 2.12.0

Here is my code sample where I am calling the actual API

@client = Savon.client(wsdl: "#{Rails.root.to_s}/app/carriers/wsdls/purolator/tracking_service/TrackingServiceDev.wsdl",
              "soap_header" => {
                "RequestContext" => {
                  "Version" => '1.2',
                  "Language" => 'en_US',
                  "GroupID" => 'xxx',
                  "RequestReference" => 'Rating Example'
                }
              },
              :basic_auth => ["xxxxxxxxxx", "xxxxxxxxx"], 
              :log => true, :pretty_print_xml => true, :element_form_default => :unqualified)
body = {
      "PIN" => {
        "Value" => 329014521622
      }
    }
@client.call(:get_delivery_details, message: body).body

Here is the Request XML that is being generated and displayed by Savon

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q12="http://purolator.com/pws/service/v1" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://purolator.com/pws/datatypes/v1" xmlns:ins1="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation" xmlns:ins2="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF">
  <env:Header>
    <RequestContext>
      <Version>1.2</Version>
      <Language>en_US</Language>
      <GroupID>xxx</GroupID>
      <RequestReference>Rating Example</RequestReference>
    </RequestContext>
  </env:Header>
  <env:Body>
    <q12:GetDeliveryDetailsRequest>
      <PIN>
        <Value>329014521622</Value>
      </PIN>
    </q12:GetDeliveryDetailsRequest>
  </env:Body>
</env:Envelope>

and here is the response I am getting back from the API

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Client</faultcode>
      <faultstring xml:lang="en-CA">Element 'RequestContext' is missing from the header</faultstring>
    </s:Fault>
  </s:Body>
</s:Envelope>

API is throwing an error message that Element 'RequestContext' is missing from the header but I provided this header and it is displayed in request as well. Can anyone please point me in the right direction and let me know what I am missing here.

Aucun commentaire:

Enregistrer un commentaire