簡體   English   中英

無法為SOAP Node.js制定響應對象

[英]Can't formulate the response object for SOAP Node.js

我正在使用node-soap編寫SOAP Node.js webservice,我無法弄清楚如何正確地制定響應。

我正在使用Web連接器Web應用程序與QuickBooks 2013集成。 客戶端將發出身份驗證請求,我可以記錄傳遞的參數,因此我知道它正在被調用,但我無法得到正確的響應。

文檔說它期待一個字符串數組作為響應。 WSDL的相關部分如下所示:

  <s:element name="authenticateResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="authenticateResult" type="tns:ArrayOfString" />
      </s:sequence>
    </s:complexType>
  </s:element>

  <s:complexType name="ArrayOfString">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" />
    </s:sequence>
  </s:complexType>

 <wsdl:message name="authenticateSoapOut">
    <wsdl:part name="parameters" element="tns:authenticateResponse" />
</wsdl:message>

<wsdl:operation name="authenticate">
  <wsdl:input message="tns:authenticateSoapIn" />
  <wsdl:output message="tns:authenticateSoapOut" />
</wsdl:operation>

 <wsdl:operation name="authenticate">
  <soap:operation soapAction="http://developer.intuit.com/authenticate" style="document" />
  <wsdl:input>
    <soap:body use="literal" />
  </wsdl:input>
  <wsdl:output>
    <soap:body use="literal" />
  </wsdl:output>
</wsdl:operation>

我嘗試了許多不同的方法來配置響應對象,但不斷從客戶端獲取錯誤(QuickBooks Web連接器)

我的JavaScript是:

    var myService = {
          'QBWebConnectorSvc': {
              'QBWebConnectorSvcSoap': {
                  authenticate: function(args) {

                           //i have tried many variations of nesting arrays/objects etc.
                    var toReturn = {
                        "ArrayOfString":[guid()," "," "," "]
                    };
                    return toReturn;
                  }
              }
          }
      }

     var xml = require('fs').readFileSync('qbwc.wsdl', 'utf8'),
          server = http.createServer(function(request,response) {
              response.end("404: Not Found: "+request.url)
          });

    server.listen(8000);

    soap.listen(server, '/wsdl', myService, xml);

不知怎的,我需要構建“ArrayOfString”,但我不知道該怎么做; 我是整個肥皂的新手。

簡短回答:

您的身份驗證功能應如下所示:

authenticate: function(args) {
    return {
        authenticateResult: { string: [guid(), {}] }
    };
}

說明:

您的代碼有一些問題,我會發布每個錯誤消息,以便將來對任何遇到相同問題的人更容易搜索。

QBWC1012:未將對象引用設置為對象的實例。

您應該在對象中返回authenticateResult ,而不是ArrayOfString

QBWC1012:由於以下錯誤消息,身份驗證失敗。 指數數組的邊界之外。

QBWC不喜歡node-soap為數組創建的XML響應。 如果你在一個對象中返回一個數組,那么這就是node-soap產生的(相關部分)(即return { authenticateResult: [guid(), ""] }

<tns:authenticateResponse xmlns:tns="http://developer.intuit.com/" xmlns="http://developer.intuit.com/">
    <tns:authenticateResult>bdaa63cf-2d26-4d6b-8a54-6f519af6e8d4</tns:authenticateResult>
</tns:authenticateResponse>

以下是QBWC的期望:

<tns:authenticateResponse xmlns:tns="http://developer.intuit.com/" xmlns="http://developer.intuit.com/">
    <tns:authenticateResult>
        <tns:string>bdaa63cf-2d26-4d6b-8a54-6f519af6e8d4</tns:string>
        <tns:string></tns:string>
    </tns:authenticateResult>
</tns:authenticateResponse>

第一個問題是名稱空間錯誤。 第二個是node-soap跳過空字符串並且不在響應中包含它,但是QBWC正在尋找它(因此索引超出范圍)。 我發布的hack-ish解決方案將解決這兩個問題:

  • authenticateResult對象中添加一個string作為其鍵的數組將更正名稱空間
  • node-soap的objectToXML解析器不會忽略空對象而不是空字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM