【问题标题】:Savon SOAP Request not workingSavon SOAP 请求不起作用
【发布时间】:2017-03-06 06:48:16
【问题描述】:

我在我的 Rails 应用程序中使用 Savon gem,我需要将我的表单字段提交给 Equifax。

这是 Equifax XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v3="http://eid.equifax.com/soap/schema/canada/v3">
   <soapenv:Header/>
   <soapenv:Body>
      <v3:InitialRequest>
         <v3:Identity>
            <v3:Name>
               <v3:FirstName>Michael</v3:FirstName>
               <v3:LastName>Smith</v3:LastName>
            </v3:Name>
            <!--1 to 3 repetitions:-->
            <v3:Address timeAtAddress="72" addressType="current">
               <v3:HybridAddress>
                  <!--1 to 6 repetitions:-->
                  <v3:AddressLine>1028 Summerville</v3:AddressLine>
                  <v3:City>Vancouver</v3:City>
                  <v3:Province>BC</v3:Province>
                  <v3:PostalCode>V7B0A8</v3:PostalCode>
               </v3:HybridAddress>
            </v3:Address>
            <!--Optional:-->
            <v3:DateOfBirth>
               <v3:Day>26</v3:Day>
               <v3:Month>08</v3:Month>
               <v3:Year>1984</v3:Year>
            </v3:DateOfBirth>
            <v3:PhoneNumber phoneType="current">
               <v3:PhoneNumber>6045556666</v3:PhoneNumber>
            </v3:PhoneNumber>
         </v3:Identity>
         <v3:ProcessingOptions>
            <v3:Language>English</v3:Language>
         </v3:ProcessingOptions>
      </v3:InitialRequest>
   </soapenv:Body>
</soapenv:Envelope>

这是我发出 SOAP 请求的 Ruby 代码。

<%= client.call(:start_transaction, message: { "v3:InitialRequest" => { "v3:Identity" => { "v3:Name" => { "v3:FirstName" => "michael", "v3:LastName" => "Smith"}, "v3:Address" => {"v3:AddressLine" => "233 Cambie St", "v3:City" => "Vancouve", "v3:Province" => "BC", "v3:PostalCode" => "V6B0E8"}, "v3:DateOfBirth" => {"v3:Day" => "26", "v3:Month" => "08", "v3:Year" => "1984"}, "v3:PhoneNumber" => {"v3:PhoneNumber" => "6048885555"}}}, attributes: { "v3:Address" => { "timeAtAddress" => "72", "addressType" => "current"}}) %>

返回的错误信息:(soap:Client) Error reading XMLStreamReader.

有人能指出正确的方向吗?

【问题讨论】:

    标签: ruby-on-rails ruby soap savon


    【解决方案1】:

    请通过发送该xml的一个字符串尝试以下方式

    xml_str = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:v3="http://eid.equifax.com/soap/schema/canada/v3"><soapenv:Header/><soapenv:Body><v3:InitialRequest><v3:Identity><v3:Name><v3:FirstName>Michael</v3:FirstName><v3:LastName>Smith</v3:LastName></v3:Name><!--1 to 3 repetitions:--><v3:Address timeAtAddress="72" addressType="current"><v3:HybridAddress><v3:AddressLine>1028 Summerville</v3:AddressLine><v3:City>Vancouver</v3:City><v3:Province>BC</v3:Province><v3:PostalCode>V7B0A8</v3:PostalCode></v3:HybridAddress></v3:Address><v3:DateOfBirth><v3:Day>26</v3:Day><v3:Month>08</v3:Month><v3:Year>1984</v3:Year></v3:DateOfBirth><v3:PhoneNumber phoneType="current"><v3:PhoneNumber>6045556666</v3:PhoneNumber></v3:PhoneNumber></v3:Identity><v3:ProcessingOptions><v3:Language>English</v3:Language></v3:ProcessingOptions></v3:InitialRequest></soapenv:Body></soapenv:Envelope>'
    
    client.call(:start_transaction, xml: xml_str)
    

    请记住,您可以使用here document 来制作 xml 字符串,但该字符串不应包含 "\n

    【讨论】:

    • 感谢您的回复。我收到“(ns1:InvalidSecurity) 处理 标头时发现错误”我认为它没有占用我的 wsse_auth。 client = Savon.client(wsse_auth: ["username", "password"], wsdl: "ifs-uat.ca.equifax.com/uru/soap/ut/canadav3?wsdl") %>
    • 我尝试通过soap_header 传递安全性,但它也不起作用。 soap_header = { "wsse:Security" => { "@soapenv:mustUnderstand" => 1, "@xmlns:soap" => "schemas.xmlsoap.org/wsdl/soap", "@xmlns:wsse" => "docs.oasis-open.org/wss/2004/01/…", " wsse:UsernameToken" =>{ "wsse:Username" => "username", "wsse:Password" => "password", "digest" => true } } }
    猜你喜欢
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多