Savon SOAP请求不起作用

时间:2017-03-06 06:48:16

标签: ruby-on-rails ruby soap savon

我在我的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)读取XMLStreamReader时出错。

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

1 个答案:

答案 0 :(得分:0)

请通过发送一个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