简体   繁体   中英

Ruby and Savon(2.3) SOAP client - Unable to connect with web service

I'm trying to use Savon(2.3) to make a SOAP request with Ruby, but I'm receiving a 500 error code from server .

Server response :-

SOAP response (status 500) D, [2014-03-04T11:44:03.824902 #10771] DEBUG -- : soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e)

Ruby code :-

require 'savon'

client = Savon.client(encoding: "UTF-8",env_namespace: :soapenv,namespace_identifier:    :web, wsdl:'http://www3.experian.co.za/webservice/getreport.asmx?wsdl')
xml = '<![CDATA[<InputData>test data in beteween </InputData>]]>'
message = {
"Input" => xml
}
response = client.call(:get_report,:message => message)

Request i wants to create :-

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://localhost/WebService/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetReport>
         <!--Optional:-->
         <web:Input><![CDATA[<InputData>(Text data in between)</InputData>]]></web:Input>
      </web:GetReport>
   </soapenv:Body>
</soapenv:Envelope>

I have tested it with soapui tool and i am getting response correctly but not with savon ruby client.

You can use Gyoku not to escape the characters in CDATA.

https://github.com/savonrb/gyoku/blob/master/README.md

message Gyoku.xml(data: "</body></xml>]]>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM