Ruby Can';我无法让Savon生成正确的XML

Ruby Can';我无法让Savon生成正确的XML,ruby,soap,wsdl,savon,Ruby,Soap,Wsdl,Savon,我以前用过肥皂,但是很多很多年以前,如果我能帮上忙,我会尽量保持清醒 短篇小说… 使用“Soap客户端”OSX应用程序,我可以得到我想要的响应 如果我使用client.request:foo\u web\u serivce,:language\u count,:body=>{:foo\u app\u id=>“…”,:session\u id=>“…”}那么我会得到一个状态200,但我的结果是-1,因为我相信app\u id无法识别 如果我尝试复制Soap客户端调用()而不是Savon的调用(

我以前用过肥皂,但是很多很多年以前,如果我能帮上忙,我会尽量保持清醒

短篇小说…

  • 使用“Soap客户端”OSX应用程序,我可以得到我想要的响应
  • 如果我使用
    client.request:foo\u web\u serivce,:language\u count,:body=>{:foo\u app\u id=>“…”,:session\u id=>“…”}
    那么我会得到一个
    状态200
    ,但我的结果是
    -1
    ,因为我相信app\u id无法识别
  • 如果我尝试复制Soap客户端调用(
    )而不是Savon的调用(
    ),那么我会得到一个
    状态500
请提前告知并感谢

说来话长……

使用SOAP客户端,我可以看到正确的请求XML是:

User-Agent: Mac OS X; WebServicesCore (357)
Content-Type: text/xml
Host: redacted
Soapaction: http://tempuri.org/redacted/LanguageCount

<?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:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
      <SOAP-ENV:Body>
        <LanguageCount xmlns="http://tempuri.org/">
          <fooAppID xsi:type="xsd:string">12345678-1234-1234-1234-123456789123</fooAppID>
          <sessionID xsi:type="xsd:string">12345678-1234-1234-1234-123456789123</sessionID>
        </LanguageCount>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
用户代理:macosx;WebServicesCore(357)
内容类型:text/xml
主持人:编辑
Soapaction:http://tempuri.org/redacted/LanguageCount
12345678-1234-1234-1234-123456789123
12345678-1234-1234-1234-123456789123
但是,当我尝试在控制台中这样做时:

ruby-1.8.7-p302 > client = Savon::Client.new do |wsdl, http, wsse|
ruby-1.8.7-p302 >       wsdl.document = "http://FooService.cloudapp.net/FooService.svc?wsdl"
ruby-1.8.7-p302 ?>  end
 => #<Savon::Client:0x1055e2dc8 @http=#<HTTPI::Request:0x1055e2bc0>, @wsse=#<Savon::WSSE:0x1055e2b98>, @wsdl=#<Savon::WSDL::Document:0x1055e2c10 @request=#<HTTPI::Request:0x1055e2bc0>, @document="http://FooService.cloudapp.net/FooService.svc?wsdl">> 
ruby-1.8.7-p302 > 
ruby-1.8.7-p302 >   client.request :language_count, :body => {:Foo_app_id => "12345678-1234-1234-1234-123456789123", :session_id => "12345678-1234-1234-1234-123456789123"}
Retrieving WSDL from: http://FooService.cloudapp.net/FooService.svc?wsdl
HTTPI executes HTTP GET using the net_http adapter
SOAP request: http://Fooservice.cloudapp.net/FooService.svc
SOAPAction: "LanguageCount", Content-Type: text/xml;charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:wsdl="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><LanguageCount><FooAppId>12345678-1234-1234-1234-123456789123</FooAppId><sessionId>12345678-1234-1234-1234-123456789123</sessionId></LanguageCount></env:Body></env:Envelope>
HTTPI executes HTTP POST using the net_http adapter
SOAP response (status 500):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action 'LanguageCount' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault></s:Body></s:Envelope>
Savon::SOAP::Fault: (a:ActionNotSupported) The message with Action 'LanguageCount' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
ruby-1.8.7-p302>client=Savon::client.new do | wsdl、http、wsse|
ruby-1.8.7-p302>wsdl.document=”http://FooService.cloudapp.net/FooService.svc?wsdl"
ruby-1.8.7-p302?>结束
=> # 
ruby-1.8.7-p302>
ruby-1.8.7-p302>client.request:language_count,:body=>{:Foo_app_id=>“12345678-1234-1234-123456789123”,:session_id=>“12345678-1234-1234-1234-123456789123”}
正在从以下位置检索WSDL:http://FooService.cloudapp.net/FooService.svc?wsdl
HTTPI使用net_HTTP适配器执行httpget
SOAP请求:http://Fooservice.cloudapp.net/FooService.svc
SOAPAction:“LanguageCount”,内容类型:text/xml;字符集=UTF-8
12345678-1234-1234-1234-12345678912312345678-1234-1234-1234-123456789123
HTTPI使用netu HTTP适配器执行httpost
SOAP响应(状态500):
答:ActionNotSupported由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理带有操作“LanguageCount”的消息。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
Savon::SOAP::Fault:(a:ActionNotSupported)由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理操作为“LanguageCount”的消息。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
但当我使用foo_web_服务的名称空间时,我得到:

 ruby-1.8.7-p302 > client = Savon::Client.new do |wsdl, http, wsse| ruby-1.8.7-p302 >       wsdl.document = "http://FooService.cloudapp.net/FooService.svc?wsdl" ruby-1.8.7-p302 ?>  end  =>
#<Savon::Client:0x105882498 @http=#<HTTPI::Request:0x105882358>, @wsse=#<Savon::WSSE:0x105882330>, @wsdl=#<Savon::WSDL::Document:0x105882380 @request=#<HTTPI::Request:0x105882358>, @document="http://FooService.cloudapp.net/FooService.svc?wsdl">> ruby-1.8.7-p302 >  ruby-1.8.7-p302 >   client.request :Foo_web_service, :language_count, :body => {:Foo_app_id
=> "12345678-1234-1234-1234-123456789123", :session_id => "12345678-1234-1234-1234-123456789123"} Retrieving WSDL from: http://FooService.cloudapp.net/FooService.svc?wsdl HTTPI executes HTTP GET using the net_http adapter SOAP request: http://Fooservice.cloudapp.net/FooService.svc SOAPAction: "http://tempuri.org/FooService/LanguageCount", Content-Type: text/xml;charset=UTF-8 <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:Foo_web_service="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><Foo_web_service:LanguageCount><FooAppId>12345678-1234-1234-1234-123456789123</FooAppId><sessionId>12345678-1234-1234-1234-123456789123</sessionId></Foo_web_service:LanguageCount></env:Body></env:Envelope> HTTPI executes HTTP POST using the net_http adapter SOAP response (status 200): <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><LanguageCountResponse xmlns="http://tempuri.org/"><LanguageCountResult>-1</LanguageCountResult></LanguageCountResponse></s:Body></s:Envelope>
=> #<Savon::SOAP::Response:0x105a2cca8 @http=#<HTTPI::Response:0x105a28ce8 @body="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><LanguageCountResponse xmlns=\"http://tempuri.org/\"><LanguageCountResult>-1</LanguageCountResult></LanguageCountResponse></s:Body></s:Envelope>", @raw_body="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><LanguageCountResponse xmlns=\"http://tempuri.org/\"><LanguageCountResult>-1</LanguageCountResult></LanguageCountResponse></s:Body></s:Envelope>", @code=200, @headers={"x-powered-by"=>"ASP.NET", "x-aspnet-version"=>"4.0.30319", "content-type"=>"text/xml; charset=utf-8", "date"=>"Sat, 02 Jul 2011 23:40:56 GMT", "server"=>"Microsoft-IIS/7.0", "content-length"=>"214", "cache-control"=>"private"}>, @soap_fault=Savon::SOAP::Fault, @http_error=Savon::HTTP::Error>  ruby-1.8.7-p302 >
ruby-1.8.7-p302>client=Savon::client.new do | wsdl,http,wsse | ruby-1.8.7-p302>wsdl.document=”http://FooService.cloudapp.net/FooService.svc?wsdl“ruby-1.8.7-p302?>结束=>
#ruby-1.8.7-p302>ruby-1.8.7-p302>client.request:Foo_web_服务,:language_count,:body=>{:Foo_app_id
=>“12345678-1234-1234-1234-123456789123”,:会话id=>“12345678-1234-1234-1234-123456789123}从以下位置检索WSDL:http://FooService.cloudapp.net/FooService.svc?wsdl HTTPI使用net_HTTP适配器SOAP请求执行HTTP GET:http://Fooservice.cloudapp.net/FooService.svc SOAPAction:“http://tempuri.org/FooService/LanguageCount",内容类型:text/xml;charset=UTF-8 12345678-1234-1234-1234-1234567812345678-1234-1234-1234-1234-1234-123456789123 HTTPI使用网络HTTP适配器SOAP响应执行HTTP POST(状态200):-1
=>#“ASP.NET”、“x-aspnet-version”=>“4.0.30319”、“内容类型”=>“text/xml;字符集=utf-8”、“日期”=>“Sat,02 Jul 2011 23:40:56 GMT”、“服务器”=>“Microsoft IIS/7.0”、“内容长度”=>“214”、“缓存控制”=>“private”}>,@soap\u fault=Savon::soap::fault、@http\u error=Savon::http::error>ruby-1.8.7-p302>

长话短说,我不得不做3个改变

  • response=client.request:language\u count
    更改为
    response=client.request“LanguageCount”
  • 添加了
    :xmlns=>”http://tempuri.org/“
    转到client.request调用的末尾
  • 显式调用SOAPaction,如:
    client.http.headers[“SOAPaction”]='”http://tempuri.org/FooService/LanguageCount“'

  • 希望这有助于某人,因为我周末一直在肥皂地狱,希望我能阻止其他人出现在那里。

    我已经计算出了第1点和第3点,但第2点为我省去了很多痛苦-谢谢!