Sachin Singh
Sachin Singh

Reputation: 7225

how to specify namespace in SOAP request with 'savon' gem?

I am using recent version of savon gem and trying to send a SOAP request i am getting this error about invalid url:

 Invalid URL: %7Bendpoint%20address%7D (ArgumentError)
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/httpi-2.3.0/lib/httpi/request.rb:27:in `url='
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/savon-2.8.0/lib/savon/operation.rb:103:in `build_request'
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/savon-2.8.0/lib/savon/operation.rb:51:in `call'
        from /home/vagrant/.rvm/gems/ruby-2.1.0/gems/savon-2.8.0/lib/savon/client.rb:36:in `call'

My code is:

require "savon"
require "excon"

Excon.defaults[:ssl_verify_peer] = false

class Payback

  attr_reader :connection, :client, :operation, :message

  SOAP_URL = "https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl"

  def initialize operation, message
    @client = Savon.client(wsdl: "https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl", ssl_verify_mode: :none)
    @operation = operation
    @message = message
  end

  def response
    @response ||= client.call(operation, message: message)
  end

end

this is how i am using it.(I know something is wrong with namespaces)

payback = Payback.new :get_account_balance,
                      {"typ:Authentication" => { "typ1:Principal" => { "typ1:PrincipalValue" => 9899012182,
                                                                       "typ1:PrincipalClassifier" => 3 }}}
payback.response

I need to construct this XML with savon

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://www.payback.net/lmsglobal/ws/v1/extint/types" xmlns:typ1="http://www.payback.net/lmsglobal/xsd/v1/types">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:GetAccountBalanceRequest>
         <typ:Authentication>
            <typ1:Principal>
               <typ1:PrincipalValue>9899012182</typ1:PrincipalValue>
               <typ1:PrincipalClassifier>3</typ1:PrincipalClassifier>
            </typ1:Principal>
         </typ:Authentication>
      </typ:GetAccountBalanceRequest>
   </soapenv:Body>
</soapenv:Envelope>

i don't know what i am doing wrong here, please help.

Upvotes: 0

Views: 1893

Answers (1)

oldhomemovie
oldhomemovie

Reputation: 15129

I noticed that on line 5820 of the WSDL file the location looks like this:

<soap:address location="{endpoint address}"/>

Could it be the problem?

Edited 1.

  1. Open up in your browser: https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl
  2. Search for {endpoint address} string on the page.

I'm far from understand this particular WSDL document, but I wonder if there must be something else in place of {endpoint address}, like a real URI. E.g. could it be the WSDL document that has the problem?

Edited 2

Tried to remove the typ and typ1 which were not recognized by the service. Ended up with a working code that returns a valid response:

puts Savon.client(
  wsdl: 'https://partnertest.payback.in/PBExternalServices/v1/soap?wsdl',
  endpoint: 'https://partnertest.payback.in/PBExternalServices/v1/soap',
  ssl_verify_mode: :none
).call(
  :get_account_balance,
  :message => {
    'Authentication' => {
      'Principal' => {
        'PrincipalValue' => 9899012182,
        'PrincipalClassifier' => 3
      }
    }
  }
)

Upvotes: 1

Related Questions