2013-12-23 4 views
3

Я пытаюсь сделать soap-сервер с node.js, используя мыло-мыло. меня какНачало работы node-soap

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 throw new Error (p.getError()); ^ Ошибка: несоответствующий тег

Как исправить это.

+0

Как вы создали wsdl. Вы писали это самостоятельно? Вы знаете, можно ли сгенерировать это с помощью узла? –

+0

Я где-то копирую учебник. –

ответ

1

В вашем файле wsdl есть ошибки. мыльный тэг не закрыт.

<soap:address 
     location="http://localhost:8000/wsdl"/> 
2
var helloService = { 
    Hello_Service: { 
    Hello_Port: { 
     sayHello: function(args) { 
     return { 
      greeting: "Hello!!!" 
     }; 
     } 
    } 
    } 
} 

исправить это в вас код (название метода и выходной параметр в вас неверный код). sayHello это soapAction в файле wsdl.