无法制定SOAP Node.js的响应对象

the*_*ite 4 javascript quickbooks soap wsdl node.js

我正在使用node-soap编写SOAP Node.js Web服务,但我不知道如何正确地制定响应。

我正在使用Web Connector将Webapp与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>
Run Code Online (Sandbox Code Playgroud)

我尝试了多种配置响应对象的方法,但是不断从客户端获取错误(QuickBooks Web Connector)

我拥有的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);
Run Code Online (Sandbox Code Playgroud)

我不知何故需要构建“ ArrayOfString”,但是我不知道该怎么做。我是整个肥皂的新手。

Joh*_*hnB 5

简短答案:

您的身份验证功能应如下所示:

authenticate: function(args) {
    return {
        authenticateResult: { string: [guid(), {}] }
    };
}
Run Code Online (Sandbox Code Playgroud)

说明:

您的代码有几处错误,我将针对每个错误消息发布错误消息,以使将来有相同问题的任何人都可以对其进行搜索。

QBWC1012:对象引用未设置为对象的实例。

您应该authenticateResult在对象中返回,而不是在ArrayOfString

QBWC1012:由于以下错误消息,身份验证失败。指数数组的边界之外。

QBWC不喜欢节点肥皂为数组创建的XML响应。如果您在对象中返回一个数组,则这是节点肥皂产生的(相关部分)(即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>
Run Code Online (Sandbox Code Playgroud)

这是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>
Run Code Online (Sandbox Code Playgroud)

第一个问题是名称空间错误。第二个是node-soap跳过空字符串,并且不将其包含在响应中,但是QBWC正在寻找它(因此索引超出范围)。我发布的hack-ish解决方案将解决以下两个问题:

  • stringauthenticateResult对象内添加一个数组作为其键将更正名称空间
  • node-soap的解析器不会忽略空对象而不是空字符串objectToXML