Search code examples
ruby-on-railsrubysoapsavon

Cannot call web service methods via SOAP Connection (SAVON) in Ruby on Rails. Where am i going wrong?


I seem to be getting this error message:

(a:ActionNotSupported) The message with Action 'GetServices' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

I assume it is something to do with the security/binding setup. My connection uses HTTP, with basichttpbinding. I've done a lot of searching for the answer, as I always do, but am unable to fix it, and no one here has expertise on Ruby on Rails.

Help would be appreciated.

Below is my code, in Ruby on Rails, which initialises the service and then calls it. Note: I can connect to it fine. It has successfully reported the available methods. Just calling the methods seems to be the problem. I have successfully connected to online test services using the same code. And I use Savon.

  def test
    puts "web_service: IN"    
    client = Savon::Client.new do
      wsdl.document = "http://hidden.co.uk/myService.svc?wsdl"
    end

    @response = client.request "GetServices", :xmlns => "http://tempuri.org/" do
      soap.header = {}
      soap.body = {
        "CostCentreNo" => 1,
        "filter" => 0
      }
    end    
    puts '##########################'
    puts @response.to_hash;   
  end

Below is what my Ruby on Rails sends:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:wsdl="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<GetServices xmlns="http://tempuri.org/">
<CostCentreNo>1</CostCentreNo>
<filter>0</filter>
</GetServices>
</env:Body>
</env:Envelope>

This is what WCF test client sends, (which works)

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IIBCSServices/GetServices</Action>
  </s:Header>
  <s:Body>
    <GetServices xmlns="http://tempuri.org/">
      <CostCentreNo>0</CostCentreNo>
      <filter>0</filter>
    </GetServices>
  </s:Body>
</s:Envelope>

Solution

  • It seems to be the way it was being called... Something so simple.

    The override Stated on the SAVON Tutorial, recommended if you have an uppercase starting camelcase doesnt work. Maybe the tutorial is outdated. (Note, :wsdl IS required in my case)

    So this was not working:

    response = client.request :wsdl, "GetCustomerCentreDetails"
    

    Changing it to:

     response = client.request :wsdl, :get_customer_centre_details
    

    Then obviously I need a body added to it, and header etc.

    The assumption that caused me confusion : Being able to get the WSDL does not mean you are connected to the webservice.