Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying SOAP XML namespace with Savon gem

I'm attempting to modify one of the namespaces in my Savon SOAP call. Here is how my request looks:

HTTPI GET request to www.intg.pathway.verosapps.com (excon)
SOAP request: https://www.intg.pathway.verosapps.com/VerosPathway.svc
SOAPAction: "urn:IVerosPathway/VerosPathway_Ping", Content-Type: text/xml;charset=UTF-8, Content-Length: 434
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <VerosPathway_Ping>
      <request>
        <Credentials>
          <UserId>*username*</UserId>
          <Password>*password*</Password>
        </Credentials>
      </request>
    </VerosPathway_Ping>
  </soapenv:Body>
</soapenv:Envelope>

I've had to do a ton of tweaking since this company expects it's clients to use .NET for their SOAP interaction and we are using Ruby. I am extremely close to getting the format correct, but I need to do one of two things in the Envelope section:

  1. Change "xmlns="http://tempuri.org/" to "xmlns:wsdl="http://tempuri.org/"
  2. OR remove "xmlns="http://tempuri.org/" completely.

Here is my Savon call:

apiClient = Savon.client(endpoint: "https://www.intg.pathway.verosapps.com/VerosPathway.svc", env_namespace: :soapenv, namespace_identifier: nil, logger: Rails.logger, log_level: :debug, log: true, :pretty_print_xml => true, ssl_version: :TLSv1, wsdl: 'https://www.intg.pathway.verosapps.com/VerosPathway.svc?wsdl')

If I add the following line to my Savon call:

namespaces: {"xmlns:wsdl" => "http://tempuri.org/"}

then my request looks like this:

HTTPI GET request to www.intg.pathway.verosapps.com (excon)
    SOAP request: https://www.intg.pathway.verosapps.com/VerosPathway.svc
    SOAPAction: "urn:IVerosPathway/VerosPathway_Ping", Content-Type: text/xml;charset=UTF-8, Content-Length: 434
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://tempuri.org/">
      <soapenv:Body>
        <VerosPathway_Ping>
          <request>
            <Credentials>
              <UserId>*username*</UserId>
              <Password>*password*</Password>
            </Credentials>
          </request>
        </VerosPathway_Ping>
      </soapenv:Body>
    </soapenv:Envelope>

So in this case I would just need to remove the "xmlns="http://tempuri.org/" line.

Any suggestions would be greatly appreciated.

Thanks!

like image 750
Brian Smith Avatar asked Jan 08 '23 13:01

Brian Smith


2 Answers

you can simply pass the hash with the options as below:

client = Savon.client(
     wsdl: "https://example.com?wsdl",
     log: true,
     log_level: :debug,
     pretty_print_xml: true,
     namespace_identifier: :mes,
     namespaces: {"xmlns:mes" => "http://example.com/messages/","xmlns:glob"=>"http://example.com/globals"}                      
) 
like image 187
Abid Iqbal Avatar answered Jan 11 '23 05:01

Abid Iqbal


I finally figured it out. All I needed to do was add the following line to my Savon call:

namespace: ""

So my final Savon call looks like:

apiClient = Savon.client(
    endpoint: "https://www.intg.pathway.verosapps.com/VerosPathway.svc",
    namespace: "", 
    env_namespace: :soapenv, 
    namespace_identifier: nil, 
    logger: Rails.logger, 
    log_level: :debug, 
    log: true, 
    :pretty_print_xml => true, 
    ssl_version: :TLSv1, 
    wsdl: 'https://www.intg.pathway.verosapps.com/VerosPathway.svc?wsdl'
)
like image 41
Brian Smith Avatar answered Jan 11 '23 03:01

Brian Smith