如何开始使用节点肥皂

问题描述 投票:4回答:2

我尝试使用node-soap使用node.js创建soap-server。我有wsdl,如

<definitions name="HelloService"
   targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
   xmlns="http://schemas.xmlsoap.org/wsdl/"
   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">

   <message name="SayHelloRequest">
    <part name="firstName" type="xsd:string"/>
   </message>
   <message name="SayHelloResponse">
    <part name="greeting" type="xsd:string"/>
   </message>

   <portType name="Hello_PortType">
    <operation name="sayHello">
       <input message="tns:SayHelloRequest"/>
       <output message="tns:SayHelloResponse"/>
    </operation>
   </portType>

   <binding name="Hello_Binding" type="tns:Hello_PortType">
   <soap:binding style="rpc"
    transport="http://schemas.xmlsoap.org/soap/http"/>
   <operation name="sayHello">
    <soap:operation soapAction="sayHello"/>
    <input>
       <soap:body
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        namespace="urn:examples:helloservice"
        use="encoded"/>
    </input>
    <output>
       <soap:body
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        namespace="urn:examples:helloservice"
        use="encoded"/>
    </output>
   </operation>
   </binding>

   <service name="Hello_Service">
    <documentation>WSDL File for HelloService</documentation>
    <port binding="tns:Hello_Binding" name="Hello_Port">
       <soap:address
        location="http://localhost:8000/wsdl">
    </port>
   </service>
</definitions>

和我的代码

var http = require('http');
var soap = require('soap');
var helloService = {
  Hello_Service: {
    Hello_Port: {
      SayHelloRequest: function(args) {
        return {
          firstName: args.name
        };
      }
    }
  }
}
var xml = require('fs').readFileSync('HelloService.wsdl', 'utf8'),
      server = http.createServer(function(request,response) {
          response.end("404: Not Found: "+request.url)
      });
server.listen(8000);
soap.listen(server, '/wsdl', helloService, xml);

并且我将它们放在相同的目录中但出现错误

/ nodejs_ws_demo / node_modules / soap / lib / wsdl.js:937抛出新的错误(p.getError());^错误:标签不匹配

我该如何解决。

node.js web-services soap wsdl soapserver
2个回答
2
投票

wsdl文件中有错误。肥皂标签未关闭。


3
投票
var helloService = {
  Hello_Service: {
    Hello_Port: {
      sayHello: function(args) {
        return {
          greeting: "Hello!!!"
        };
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.