Node.js 使用节点soap的简单Web服务

Node.js 使用节点soap的简单Web服务,node.js,web-services,soap,wsdl,Node.js,Web Services,Soap,Wsdl,我试图使用nodejs和nodesoap使用SOAP实现一个简单的web服务,但是客户端似乎在使用服务器时遇到了问题 assert.js:92 throw new assert.AssertionError({ ^ AssertionError: invalid message definition for document style binding 我的wsdl文件是: <?xml version="1.0" encoding="UTF-8"?> <w

我试图使用nodejs和nodesoap使用SOAP实现一个简单的web服务,但是客户端似乎在使用服务器时遇到了问题

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: invalid message definition for document style binding
我的wsdl文件是:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="wscalc1"
                  targetNamespace="http://localhost:8000/wscalc1"
                  xmlns="http://localhost:8000/wscalc1"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

  <wsdl:message name="sumarRequest">
    <wsdl:part name="a" type="xs:string"></wsdl:part>
    <wsdl:part name="b" type="xs:string"></wsdl:part>
  </wsdl:message>

  <wsdl:message name="multiplicarRequest">
    <wsdl:part name="a" type="xs:string"></wsdl:part>
    <wsdl:part name="b" type="xs:string"></wsdl:part>
  </wsdl:message>

  <wsdl:message name="multiplicarResponse">
    <wsdl:part name="res" type="xs:string"></wsdl:part>
  </wsdl:message>

  <wsdl:message name="sumarResponse">
    <wsdl:part name="res" type="xs:string"></wsdl:part>
  </wsdl:message>


  <wsdl:portType name="calcP">
    <wsdl:operation name="sumar">
      <wsdl:input message="sumarRequest"></wsdl:input>
      <wsdl:output message="sumarResponse"></wsdl:output>
    </wsdl:operation>

    <wsdl:operation name="multiplicar">
      <wsdl:input message="multiplicarRequest"></wsdl:input>
      <wsdl:output message="multiplicarResponse"></wsdl:output>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="calcB" type="calcP">
    <soap:binding style="document" 
                  transport="http://schemas.xmlsoap.org/soap/http"/>

    <wsdl:operation name="sumar">
      <soap:operation soapAction="sumar"/>
      <wsdl:input>
        <soap:body use="literal" 
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" 
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:output>
    </wsdl:operation>

    <wsdl:operation name="multiplicar">
      <soap:operation soapAction="multiplicar"/>
      <wsdl:input>
        <soap:body use="literal" 
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" 
                   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="ws">
    <wsdl:port name="calc" binding="calcB">
      <soap:address location="http://localhost:8000/wscalc1"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
client.js

var soap = require('soap');
var url = 'http://localhost:8000/wscalc1?wsdl';
soap.createClient(url, function(err, client) {

    if (err) throw err;


    console.log(client.describe().ws.calc);

    client.multiplicar({"a":"1","b":"2"},function(err,res){
        if (err) throw err;

        console.log(res);
    });
});
使用该代码,输出为:

{ sumar: 
   { input: { a1: 'Request', b1: 'Request' },
     output: { res: 'Response' } },
  multiplicar: 
   { input: { a2: 'Request', b2: 'Request' },
     output: { res: 'Response' } } }

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: invalid message definition for document style binding
   { sumar:
   { input: { a: 'xs:string', b: 'xs:string' },
     output: { sumres: 'xs:string' } },
  multiplicar:
   { input: { a: 'xs:string', b: 'xs:string' },
     output: { mulres: 'xs:string' } } }
   { mulres: '12' }
   { sumres: '7' }

在wsdl文件中,任何帮助都将得到极大的感谢。我所改变的是从文档到rpc的样式,尝试使用client.js获取另一个响应

我收到的是这个输出

{ sumar: 
   { input: { a: 'xs:string', b: 'xs:string' },
     output: { res: 'xs:string' } },
  multiplicar: 
   { input: { a: 'xs:string', b: 'xs:string' },
     output: { res: 'xs:string' } } }
{ res: '2' }

正如user672320所指出的,client.js失败的原因是所使用的wsdl格式为“RPC/literal”,但样式设置为“document”,而不是RPC

事实上,wsdl可以使用五种格式中的任何一种,每种格式都有不同的格式

有关使用哪种样式的讨论,请参见

此外,给出的示例也不完整

有关扩展版本,请参见下文:

wsdl文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="wscalc1" targetNamespace="http://localhost:8000/wscalc1" xmlns="http://localhost:8000/wscalc1" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <wsdl:message name="sumarRequest">
    <wsdl:part name="a" type="xs:string"/>
    <wsdl:part name="b" type="xs:string"/>
  </wsdl:message>
  <wsdl:message name="multiplicarRequest">
    <wsdl:part name="a" type="xs:string"/>
    <wsdl:part name="b" type="xs:string"/>
  </wsdl:message>
  <wsdl:message name="multiplicarResponse">
    <wsdl:part name="mulres" type="xs:string"/>
  </wsdl:message>
  <wsdl:message name="sumarResponse">
    <wsdl:part name="sumres" type="xs:string"/>
  </wsdl:message>
  <wsdl:portType name="calcP">
    <wsdl:operation name="sumar">
      <wsdl:input message="sumarRequest"/>
      <wsdl:output message="sumarResponse"/>
    </wsdl:operation>
    <wsdl:operation name="multiplicar">
      <wsdl:input message="multiplicarRequest"/>
      <wsdl:output message="multiplicarResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="calcB" type="calcP">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sumar">
      <soap:operation soapAction="sumar"/>
      <wsdl:input>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="multiplicar">
      <soap:operation soapAction="multiplicar"/>
      <wsdl:input>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="ws">
    <wsdl:port binding="calcB" name="calc">
      <soap:address location="http://localhost:8001/wscalc1"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
client.js:

var soap = require('soap');
var url = 'http://localhost:8001/wscalc1?wsdl';

soap.createClient(url, function(err, client) {
    if (err) throw err;
    console.log(client.describe().ws.calc);
    client.multiplicar({a: 4,b: 3},function(err,res){
        if (err) throw err;
        console.log(res);
    });
    client.sumar({a: 4,b: 3},function(err,res){
        if (err) throw err;
        console.log(res);
    });
});
因此,代码输出为:

{ sumar: 
   { input: { a1: 'Request', b1: 'Request' },
     output: { res: 'Response' } },
  multiplicar: 
   { input: { a2: 'Request', b2: 'Request' },
     output: { res: 'Response' } } }

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: invalid message definition for document style binding
   { sumar:
   { input: { a: 'xs:string', b: 'xs:string' },
     output: { sumres: 'xs:string' } },
  multiplicar:
   { input: { a: 'xs:string', b: 'xs:string' },
     output: { mulres: 'xs:string' } } }
   { mulres: '12' }
   { sumres: '7' }

当我使用soap调用尝试这个示例时,知道为什么名称空间是未定义的吗?6.