1

I am trying to make a SOAP request using the ruby library Savon.

I am using the following code:

require "savon"

Savon.configure do |config|
    config.soap_version = 2  # use SOAP 1.2
    config.raise_errors = false
end

wsdl_logon = Savon::Client.new do
    wsdl.document = "https://api.affili.net/V2.0/Logon.svc?wsdl"
end

username = 'XXX'
password = 'YYY'

wsdl_logon.http.headers["Content-Type"] = "text/xml; charset=utf-8"

response = wsdl_logon.request "Logon" do
  soap.body = {'Username' => username, 'Password' => password, 'WebServiceType' => 'Product'}
end

if response.http_error?
    puts "Http Error!"
    puts y response.http_error
else
    puts "No Http Error!"
end

But I keep receiving 400 error messages ("bad request"). Or, if I remove the following line

wsdl_logon.http.headers["Content-Type"] = "text/xml; charset=utf-8"

I am receiving 415 error messages ("unsupported media type").

I have been using PHP to make these requests until now, and the following code always worked without problems:

$soap_logon = new SoapClient('https://api.affili.net/V2.0/Logon.svc?wsdl');
$token = $soap_logon->Logon(array(
    'Username'      => 'XXX',
    'Password'      => 'YYY',
    'WebServiceType'    => 'Product'
));

Can anybody point me to the right direction what a possible error source might be? I am completely lost right now.

Thank you for your help.


I did as Tom De Leu suggested, and tried to remove as many differences in the generated SOAP requests in question as possible. But I still keep receiving 400 errors. Any hint on possible reasons for this would be highly appreciated.

This is the (working) Request generated by PHP (linebreaks in XML added for clarity):

POST /V2.0/Logon.svc HTTP/1.1
Host: api.affili.net
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.0-8+etch16
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://affilinet.framework.webservices/Svc/ServiceContract1/Logon"
Content-Length: 456

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://affilinet.framework.webservices/types"
    xmlns:ns2="http://affilinet.framework.webservices/Svc"
>
    <SOAP-ENV:Body>
        <ns2:LogonRequestMsg>
            <ns1:Username>xxx</ns1:Username>
            <ns1:Password>yyy</ns1:Password>
            <ns1:WebServiceType>Product</ns1:WebServiceType>
        </ns2:LogonRequestMsg>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This is the (not working) request generated by Ruby (again, xml linebreaks added for clarity)

SOAP request: https://api.affili.net/V2.0/Logon.svc
Content-Type: text/xml; charset=utf-8, SOAPAction: http://affilinet.framework.webservices/Svc/ServiceContract1/Logon, Content-Length: 605

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsdl="http://affilinet.framework.webservices/Svc"
    SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://affilinet.framework.webservices/types"
    xmlns:ns2="http://affilinet.framework.webservices/Svc"
>
    <SOAP-ENV:Body>
        <ns2:LogonRequestMsg>
            <ns1:Username>XXX</ns1:Username>
            <ns1:Password>YYY</ns1:Password>
            <wsdl:WebServiceType>Product</wsdl:WebServiceType>
        </ns2:LogonRequestMsg>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


HTTPI executes HTTP POST using the httpclient adapter
SOAP response (status 400):
Gordon
  • 312,688
  • 75
  • 539
  • 559
Majiy
  • 1,890
  • 2
  • 24
  • 32

3 Answers3

4

I found that I needed to add the headers in to get past the 415 error.

Savon.client(wsdl: "www.sample_doman.com/endpoint?wsdl", headers: {'Content-Type' => 'application/soap+xml; charset=utf-8'})

surgentt
  • 399
  • 1
  • 3
  • 10
2

I would suggest looking at the XML sent by the PHP code, then comparing it with the XML sent by the Ruby Savon code, and check where the differences are. Then see whether you can modify your ruby code to generate the correct request.

Tom De Leu
  • 8,144
  • 4
  • 31
  • 30
0

Telling Savon to use SOAP version 2 (really 1.2) and then manually setting the content type to text/xml kind of defeats the purpose.

If your web service requires SOAP 1.2, then it is expecting a content type of 'application/soap+xml', which SAVON will do for you if you set the soap_version to 2.

If you want a content type of text/xml, just set your soap_version config variable to 1

Tom Chapin
  • 3,276
  • 1
  • 29
  • 18