soapruby-on-rails-3.1savon

Savon HTTP::ERROR but no more information?


I am trying to configure my rails app to talk to a soap webservice using this code:

client = Savon::Client.new do
  wsdl.document = "http://services.carsolize.com/BookingServices/dynamicdataservice.svc?wsdl"
end

response = client.request "ServiceRequest", "xmlns" => "http://tempuri.org/" do |soap, wsdl|
  client.http.headers["SOAPAction"] = '"http://tempuri.org/IDynamicDataService/ServiceRequest"'
  soap.body = {
    "rqst" => {
      "Credentials" => {
        "UserName" => 'user',
        "Password"  => 'pass'
      },
      "RequestType" => "Login", 
      "TypeOfService" => "Unknown",
    },
  }
end

But all I get is a Savon::HTTP::Error in HomeController#index (and no more info) for the line starting with response.


Solution

  • I've tried to do it this way

    client = Savon.client 'http://services.carsolize.com/BookingServices/dynamicdataservice.svc?wsdl'
    
    username = '*********'
    password = '*********'
    
    response = client.request :wsdl, :login do
      http.headers["SOAPAction"] = '"http://tempuri.org/IDynamicDataService/ServiceRequest"'
      soap.xml = "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><ServiceRequest xmlns='http://tempuri.org/'><rqst xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><Credentials xmlns=''>
      <Password>#{password}</Password><UserName>#{username}</UserName></Credentials><RequestType xmlns=''>Login</RequestType><TypeOfService xmlns=''>Unknown</TypeOfService></rqst></ServiceRequest></s:Body></s:Envelope>"
    end
    

    And it works fine