루비

2010-06-28 2 views
3
에 Savon 보석을 사용하여 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에 관해서는 초보자이기 때문에 비누 : Body 태그의 xml 태그 순서가 중요한지 아닌지 알려주시겠습니까?

답변

8

Steve 덕분에 Nick과 Steve가 비슷한 문제에 대해 이야기하고있는 "Why is “wsdl” namespace interjected into action name when using savon for ruby soap communication?"을 발견했습니다.

닉처럼 내 문제는 Savon이 SOAP 봉투를 요리하는 방식에있었습니다. Nick의 추천에 따라, 나는 Savon SOAP 클래스에서 두 가지 방법으로 패치하는 원숭이를 끝내었다. lib/savon/soap.rb에 있습니다. 그리고 지금 가볼만합니다.

SOAP에 관해서 초보자이고 SOAP 클라이언트를 작성한 것은 처음이지만 솔직히 말해서! 나는 아직도 REST 서비스를위한 클라이언트를 작성하고 그것이 재미 있었다는 것을 처음으로 기억한다.

REST ROCKS, SOAP SUCKS. 그게 다야!

+2

upvoted "그러나 정직하게 그것 SUCKS!", 비록 나가 찾고있는 응답을 찾아 내지 않았다;) –

3

<request> 요소가 누락되었습니다.

soap.body을 키가 ::request이고 이미있는 기존 해시 레코드의 값으로 단일 해시로 바꾸어보세요.


편집 1 :

코드 내에서 네임 스페이스 라인이 있어야 할 "https://webservices.sveaekonomi.se/webpay"이 아닌 전체 URL 당신은 현재이 있습니다.

+0

언급 해 주셔서 감사합니다. 요청 태그를 추가했지만 여전히 오류가 발생합니다. 하나는 savon이 env 태그를 생성하는 반면 soap 태그는 생성해야한다는 것입니다. 둘 다 xmlns 속성을 공유하고 있습니까? 그것은 problm의 원천이 될 수 있을까요? 다른 것은 CreateOrder 태그입니다. 사양은

+0

과 같은 다른 문제를 생성하면서 savon이 일부를 생성하는 동안 와 같은 것을 요청했습니다. –