Savon is returning no result in Rails 4?

末鹿安然 提交于 2019-12-25 03:11:08

问题


I have asked this question in here Savon 2 returns nothing

And got the answer. Thanks to +Steffen Roller

Now most of my Soap API are sorted. With this one, I have tried everything still nothing I get. I thought it should work as the USZip worked. Apparently not :(

Soap API:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetHistoryByID>
         <!--Optional:-->
         <tem:personId>789834133</tem:personId>
      </tem:GetHistoryByID>
   </soapenv:Body>
</soapenv:Envelope>

SoapUI response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetHistoryByIDResponse xmlns="http://tempuri.org/">
         <GetHistoryByIDResult xmlns:a="http://schemas.datacontract.org/2004/07/Domain.MySite.WS" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:ErrorMessage i:nil="true"/>
            <a:Rounds xmlns:b="http://schemas.datacontract.org/2004/07/Domain.MySite.WS">
               <b:Round>
                  <b:AdjustedGross>104</b:AdjustedGross>
                  <b:MainField>14</b:MainField>
               </b:Round>
               <b:Round>
                  <b:AdjustedGross>101</b:AdjustedGross>
                  <b:MainField>14</b:MainField>
               </b:Round>
            </a:Rounds>
            <a:Status>Success</a:Status>
         </GetHistoryByIDResult>
      </GGetHistoryByIDResponse>
   </s:Body>
</s:Envelope>

Here is my Savon

  require 'savon'
   require 'pp'

   a_url = 'wsdl link in here'

   client = Savon.client(
           wsdl: a_url,
           log: true, # set true to switch on logging
           log_level: :debug,
           pretty_print_xml: true
   )

   person_id =  "12345"

   response = client.call(:get_history_by_id,  message: { "personId" => person_id }
   )

And response is this:

{:get_history_by_id_response=>{:get_history_by_id_result=>{:error_message=>nil, :rounds=>{:"@xmlns:b"=>"http://schemas.datacontract.org/2004/07/Domain.MySite.Entities"}, :status=>"Success", :"@xmlns:a"=>"http://schemas.datacontract.org/2004/07/Domain.MySite.WS", :"@xmlns:i"=>"http://www.w3.org/2001/XMLSchema-instance"}, :@xmlns=>"http://tempuri.org/"}} 

Thanks again guys.

Update: Savon log:

D, [2014-06-13T10:14:56.457008 #3157] DEBUG -- : HTTPI GET request to api.mysite.com.au (httpclient)
I, [2014-06-13T10:14:56.569055 #3157]  INFO -- : SOAP request: http://api.mysite.com.au/MyDomain/DomainCCService.svc
I, [2014-06-13T10:14:56.569113 #3157]  INFO -- : SOAPAction: "http://tempuri.org/IDomainCCService/GetHistoryById", Content-Type: text/xml;charset=UTF-8, Content-Length: 382
D, [2014-06-13T10:14:56.569214 #3157] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <tns:GetHistoryById>
      <personId>789834133</personId>
    </tns:GetHistoryById>
  </soapenv:Body>
</soapenv:Envelope>

D, [2014-06-13T10:14:56.569418 #3157] DEBUG -- : HTTPI POST request to api.mysite.com.au (httpclient)
I, [2014-06-13T10:14:56.902413 #3157]  INFO -- : SOAP response (status 200)
D, [2014-06-13T10:14:56.902625 #3157] DEBUG -- : <?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <GetHistoryByIdResponse xmlns="http://tempuri.org/">
      <GetHistoryByIdResult xmlns:a="http://schemas.datacontract.org/2004/07/Domain.MySite.WS" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:ErrorMessage i:nil="true"/>
        <a:Rounds xmlns:b="http://schemas.datacontract.org/2004/07/Domain.MySite.Entities"/>
        <a:Status>Success</a:Status>
      </GetHistoryByIdResult>
    </GetHistoryByIdResponse>
  </s:Body>
</s:Envelope>

Thanks


回答1:


The simplest solution is to include the namespace into your tag. At least that's what I use to do. Replace "personID" with "tns:personID". That should do it.



来源:https://stackoverflow.com/questions/24195706/savon-is-returning-no-result-in-rails-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!