0

I am trying to call a web service using Savon. The request I am trying to generate is this (this is a valid request that is working, generated with wizdler):

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <FraudValidationRequest xmlns="http://schemas.gid.gap.com/fraudvalidation/v3">
            <OrderHeader xmlns="">
                <EntryType>1</EntryType>
.... more attributes

But I get something like this:

<?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:wsdl="http://schemas.gid.gap.com/fraudvalidation/v3"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <wsdl:validateOrder>
      <fraudValidationRequest>
        <orderHeader>
          <entryType>1</entryType>
        </orderHeader>
      </fraudValidationRequest>
    </wsdl:validateOrder>
  </env:Body>
</env:Envelope>

So I get this error in the server side (the web service is implemented in java):

org.apache.axis2.databinding.ADBException: Unexpected subelement FraudValidationRequest

This is my client code in ruby:

require "savon"
URL = 'http://localhost:8080/MockFraudValidationServiceProvider/services/FraudValidationServiceV3'
begin
    client = Savon.client do
        # wsdl URL + "?wsdl"
        endpoint URL
        namespace "http://schemas.gid.gap.com/fraudvalidation/v3"
        log_level :debug
        pretty_print_xml :true
    end
    response = client.call(:validate_order,
        message: {
            FraudValidationRequest: { OrderHeader: { EntryType: 1 } } 
        }
    )
    puts response.to_hash;
end

I have tried several things: wsdl, endpoint and namespace, with/without namespace, camelcase or not, etc. but I can't generate the appropriate request. I am not expert on SOAP (obviously), I understand that if there is a WSDL (my case) there is no need to set the namespace, but I am not sure. When I try using only WSDL I get this:

<?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:types="http://services.gid.gap.com/fraudvalidation/v3"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ins0="http://schemas.gid.gap.com/fraudvalidation/v3">
  <env:Body>
    <types:FraudValidationRequest>
      <fraudValidationRequest>
        <orderHeader>
          <entryType>1</entryType>
        </orderHeader>
      </fraudValidationRequest>
    </types:FraudValidationRequest>
  </env:Body>
</env:Envelope>

Please advice, I hope I was clear.

Boris Lopez
  • 516
  • 8
  • 14
  • have you tried to create manually a SOAP call using SoapUI? That would be the starting point. Then you should share the XML document of a correct SOAP call to your interface. – Steffen Roller Aug 02 '13 at 13:15
  • in the first part of my question I have shared a correct call generated with [wizdler](https://chrome.google.com/webstore/detail/wizdler/oebpmncolmhiapingjaagmapififiakb?hl=en). – Boris Lopez Aug 02 '13 at 14:16

1 Answers1

1

Have you tried this?

require 'savon'

# create a client for the service
client = Savon.client(wsdl: 'http://service.example.com?wsdl')

p client.operations
# => [:find_user, :list_users]

# call the 'findUser' operation
response = client.call(:find_user, message: { id: 42 })

response.body
# => { find_user_response: { id: 42, name: 'Hoff' } }

client operations are the ones you can call, simply you can print them and check to call the right one. message is a client parameter were you put your params, you can also set it this way:

params = {
  :param_1 => "value",
  _param_2 => 7
}
response = client.call(:find_user, message: params)

I use this code and I was able to call my Web Service

Pietro Allievi
  • 386
  • 6
  • 14