我有以下WSDL,從soapUI生成。當我測試soapUI的 請求時,它工作正常,但從savon中拋出異常。 我在Linux上使用savon 0.9.2。簡單的Savon SOAP請求不起作用
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:mes="http://www.domain.com/sub/05/00/Messages">
<soapenv:Header/>
<soapenv:Body>
<mes:loginRequest>
<!--Optional:-->
<mes:Username>admin</mes:Username>
<!--Optional:-->
<mes:Password>pass</mes:Password>
<!--Optional:-->
<mes:ImpersonationUsername></mes:ImpersonationUsername>
<!--Optional:-->
<mes:ApplicationName></mes:ApplicationName>
</mes:loginRequest>
</soapenv:Body>
</soapenv:Envelope>
腳本,這會導致錯誤:
require 'rubygems'
require 'savon'
require 'pp'
client = Savon::Client.new "http://domain/Service.asmx?WSDL"
response = client.request(:mes, "login") do
soap.body = {
"mes:Username" => "test",
"mes:Password" => "test",
"mes:ImpersonationUsername"=>"Test",
"mes:ApplicationName"=>"test"
}
end
pp response.to_hash
輸出:
D, [2011-05-10T16:06:14.316827 #11254] DEBUG -- : <?xml version="1.0"
encoding="utf-8"?><soap:Envelope xmlns:soap="http://
schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/
XMLSchema"><soap:Body><LoginResult xmlns="http://www.domain.com/sub/
05/00/
Messages"><ErrorDetails><Items><SfExceptionItem><ExceptionType>System.NullReferenceException</
ExceptionType><AssemblyName>mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b73a5c561934e089</
AssemblyName><Message>Object reference not set to an instance of an
object.</Message></SfExceptionItem></Items><FaultCode>UnknownError</
FaultCode><Message>Object reference not set to an instance of an
object.</Message></ErrorDetails></LoginResult></soap:Body></
soap:Envelope>
{:login_result=>
{:error_details=>
{:items=>
{:sf_exception_item=>
{:message=>"Object reference not set to an instance of an
object.",
:exception_type=>"System.NullReferenceException",
:assembly_name=>
"mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b73a5c561934e089"}},
:message=>"Object reference not set to an instance of an
object.",
:fault_code=>"UnknownError"},
:xmlns=>
"http://www.domain.com/sub/05/00/Messages"}}
從了SoapUI的輸出如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<LoginResult xmlns="http://domain/sub/05/00/Messages">
<UserTicket>95bfaa81149f4c118c8724b837235cd5</UserTicket>
</LoginResult>
</soap:Body>
</soap:Envelope>
通過github(https://github.com/rubiii)與我聯繫,明天我會看看這個! – rubiii 2011-05-11 22:02:54
您是否嘗試過使用Fiddler來查看SoapUI和Savon之間的請求有何不同? – Castrohenge 2013-09-20 12:06:04