4

我正在尝试与肥皂服务通信,我知道我应该像这样发送一个 SOAP 信封:

POST /webpay_test/SveaWebPay.asmx HTTP/1.1
Host: webservices.sveaekonomi.se
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://webservices.sveaekonomi.se/webpay/CreateOrder"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CreateOrder xmlns="https://webservices.sveaekonomi.se/webpay">
      <request>
        <Order>
          <ClientOrderNr>string</ClientOrderNr>
          <CustomerReference>string</CustomerReference>
          <OrderDate>dateTime</OrderDate>
          <CountryCode>string</CountryCode>
          <SecurityNumber>string</SecurityNumber>
          <CustomerEmail>string</CustomerEmail>
          <IsCompany>boolean</IsCompany>
          <PreApprovedCustomerId>long</PreApprovedCustomerId>
          <AddressSelector>string</AddressSelector>
        </Order>
        <InvoiceRows>
          <ClientInvoiceRowInfo>
            <ArticleNr>string</ArticleNr>
            <Description>string</Description>
            <PricePerUnit>double</PricePerUnit>
            <NrOfUnits>double</NrOfUnits>
            <Unit>string</Unit>
            <VatPercent>int</VatPercent>
            <DiscountPercent>int</DiscountPercent>
            <ClientOrderRowNr>int</ClientOrderRowNr>
          </ClientInvoiceRowInfo>
          <ClientInvoiceRowInfo>
            <ArticleNr>string</ArticleNr>
            <Description>string</Description>
            <PricePerUnit>double</PricePerUnit>
            <NrOfUnits>double</NrOfUnits>
            <Unit>string</Unit>
            <VatPercent>int</VatPercent>
            <DiscountPercent>int</DiscountPercent>
            <ClientOrderRowNr>int</ClientOrderRowNr>
          </ClientInvoiceRowInfo>
        </InvoiceRows>
      </request>
    </CreateOrder>
  </soap:Body>
</soap:Envelope>

这是我写的代码:

client = Savon::Client.new("https://webservices.sveaekonomi.se/webpay_test/SveaWebPay.asmx?wsdl")
res = client.create_order do |soap|  
    soap.namespace = "https://webservices.sveaekonomi.se/webpay_test/CreateOrder.asmx"
    soap.body = { :auth         => {  :username => "username", :password => "pass", :client_number => "1111" }, 
                  :order        => {  :client_order_nr => "1000000", :customer_reference => "4212", :order_date => Date.today, 
                                      :country_code => "SE", :security_number => "1111111111", :is_company => false, 
                                      :customer_email => "me@gmail.com", :pre_approved_customer_id => 0 },
                  :invoice_rows => { :client_invoice_row_info => { :article_nr => "x100", :description => "something cool -- description",
                                      :price_per_unit => 100, :nr_of_units => 3, :unit => "SEK", :vat_percent => 25,
                                      :discount_percent => 0, :client_order_row_nr => "1"},
                                     :client_invoice_row_info => { :article_nr => "x200", :description => "something cooler -- description",
                                      :price_per_unit => 200, :nr_of_units => 2, :unit => "SEK", :vat_percent => 25,
                                      :discount_percent => 0, :client_order_row_nr => "1" }  
                                   }
    }
end

它会生成这个,这与我作为模板所拥有的不同,这就是我收到错误的原因:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:wsdl="https://webservices.sveaekonomi.se/webpay_test/CreateOrder.asmx" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wsdl:CreateOrder>
<invoiceRows>
  <clientInvoiceRowInfo>
    <clientOrderRowNr>1</clientOrderRowNr>
    <pricePerUnit>200</pricePerUnit>
    <nrOfUnits>2</nrOfUnits>
    <unit>SEK</unit>
    <vatPercent>25</vatPercent>
    <articleNr>x200</articleNr>
    <discountPercent>0</discountPercent>
    <description>something cooler -- description</description>
  </clientInvoiceRowInfo>
</invoiceRows>
<order>
    <customerEmail>me@gmail.com</customerEmail>
    <preApprovedCustomerId>0</preApprovedCustomerId>
    <countryCode>SE</countryCode>
    <clientOrderNr>1000000</clientOrderNr>
    <securityNumber>11111111</securityNumber>
    <customerReference>4212</customerReference>
    <isCompany>false</isCompany>
    <orderDate>2010-06-28</orderDate>
</order>
<auth>
    <password>pass</password>
    <clientNumber>1111</clientNumber>
    <username>username</username>
</auth>
</wsdl:CreateOrder>
</env:Body>
</env:Envelope>

这是回应:

<?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>
    <CreateOrderResponse xmlns="https://webservices.sveaekonomi.se/webpay">
      <CreateOrderResult>
        <Accepted>false</Accepted>
        <ErrorMessage>Failed to create or authorize order</ErrorMessage>
        <SveaOrderNr>0</SveaOrderNr>
        <RejectionCode>Error</RejectionCode>
        <WillBuyInvoices xsi:nil="true" />
        <AuthorizeId>0</AuthorizeId>
        <AuthorizedAmount xsi:nil="true" />
        <ExpirationDate xsi:nil="true" />
      </CreateOrderResult>
    </CreateOrderResponse>
  </soap:Body>
</soap:Envelope>

谁能告诉我如何解决这个问题。并且由于我是 SOAP 的新手,您是否还会告诉我 soap:Body 标记中 xml 标记的顺序是否重要?

4

2 回答 2

9

感谢史蒂夫,我发现了“为什么在使用 savon 进行 ruby​​ soap 通信时,“wsdl”命名空间会插入到动作名称中? ”尼克和史蒂夫在那里讨论了类似的问题。

和 Nick 一样,我的问题在于 Savon 制作 SOAP 信封的方式。按照 Nick 的建议,我最终在 Savon SOAP 类中修补了几个方法。它在 lib/savon/soap.rb 中,我现在可以开始了。

当谈到 SOAP 时,我是一个新手,这是我第一次编写 SOAP 客户端,但老实说,它很糟糕!我仍然记得我第一次为 REST 服务编写客户端,天哪,这很有趣。

休息摇滚,肥皂糟透了。就这样!

于 2010-06-29T13:29:57.370 回答
3

您缺少<request>元素。

尝试用您已经拥有的现有哈希记录soap.body的键和值替换单个哈希。::request


编辑1:

您的代码中的命名空间行不应是"https://webservices.sveaekonomi.se/webpay"您当前拥有的完整 URL。

于 2010-06-28T16:08:26.997 回答