2010-06-28 149 views
3
SOAP服務談

我試圖用肥皂服務進行溝通,我知道我應該發送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 => "[email protected]", :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>[email protected]</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標籤的順序是否重要?

回答

8

感謝史蒂夫,我發現「Why is 「wsdl」 namespace interjected into action name when using savon for ruby soap communication?」尼克和史蒂夫在談論類似的問題。

像尼克一樣,我的問題在於薩翁正在烹飪SOAP信封的方式。正如Nick所推薦的,我最終在Savon SOAP類中爲猴子修補了幾個方法。它在lib/savon/soap.rb ,我現在很好。

對於SOAP而言,我是新手,這是我第一次編寫SOAP客戶端,但老實說它是成功的!我還記得我第一次爲REST服務編寫客戶端,而且很有趣。

REST ROCKS,SOAP SUCKS。就這樣!

+2

upvoted for「but honestly it SUCKS!」, 儘管我沒有找到我正在尋找的答案;) – 2012-05-01 13:01:13

3

您缺少<request>元素。

嘗試用一個密鑰::request的單個散列替換您的soap.body以及您已有的現有散列記錄的值。


編輯1:

代碼中你的命名空間線應"https://webservices.sveaekonomi.se/webpay"並非完整的網址你那裏現在。

+0

謝謝你提到的。我添加了請求標記,但仍然出現錯誤。有一點是savon生成env標籤,而它應該是肥皂標籤。儘管兩者都共享相同的xmlns屬性?它可能是問題的根源嗎? 另一件事是在CreateOrder標籤上。規範要求像,而savon生成一些像這樣的 2010-06-29 10:21:21

+0

編輯了另一個可能的問題。 – 2010-06-29 11:31:48