Reputation: 345
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.
Upvotes: 0
Views: 1623
Reputation: 79
I was facing the same error although it's not timely answer BUT posting it may in future this could be helpful for someone.
Implement OAuth2.0 with Savon
we need to put content type in request headers "Content-Type" => "text/xml"
along with Bearer token
client = Savon.client(
wsdl: [URL],
logger: Rails.logger,
log_level: :debug,
log: true,
ssl_ca_cert_file: file_path,
ssl_verify_mode: :none,
headers: { "Authorization" => "Bearer #{auth_token}", "Content-Type" => "text/xml" },
follow_redirects: true
)
Upvotes: 1
Reputation: 371
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
Upvotes: 0