开发者

Simple Savon SOAP request not working

I have the following WSDL, generated from soapUI. When I test the request from soapUI, it works fine but throws exception from savon. I am using savon 0.9.2 on Linux.

<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>

The script, which causes Errors:

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

The Output:

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</
Except开发者_JS百科ionType><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"}} 

The output from SoapUI is the following:

<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>


You might want to set the namespace in your savon request: client.namespaces["xmlns:mes"] = "http://www.domain.com/sub/05/00/Messages"


the request you send creates the following soap message

  <?xml version="1.0" encoding="UTF-8"?>
    <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:mes="urn:namespace.com"
                  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <mes:login>
    <mes:Username>test</mes:Username>
    <mes:Password>test</mes:Password>
    <mes:ImpersonationUsername>Test</mes:ImpersonationUsername>
    <mes:ApplicationName>test</mes:ApplicationName>
    </mes:login>
  </env:Body>

I guess that's not what your intention is? please insert the following lines into your code after the .new

Savon.configure do |c|
  c.log = true
end

that shows the outgoing message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜