I am trying to create a simple web service in node-js using node-soap. I have followed the example in the node-soap page here https://github.com/vpulim/node-soap
I am comsuming the web service in a visual studio project and it is allowing me to reference the web service and create the object ok in the project. When trying to call the sayHello method however I get an error complaining about the response not being 'text/xml' which is due to the error below.
Am I setting up the server file wrong or is my wsdl incorrect?
Here is my wsdl file
<?xml version="1.0"?>
<definitions name="HelloService"
targetNamespace="http://localhost:8000/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost:8000/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/SayHello" />
</port>
</service>
</definitions>
And here is my server file.
var fs = require("fs");
var soap = require('soap');
var http = require('http');
function start() {
var myService = {
Hello_Service: {
Hello_Port: {
sayHello: function(args) {
return {
firstName: args.name
};
}
}
}
}
xml = fs.readFileSync('wsdl/HelloService.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
//response.end("404: Not Found: "+request.url)
response.end(xml);
});
server.listen(8000);
var s = soap.listen(server, '/SayHello', myService, xml);
s.log = function(type, data) {
// type is 'received' or 'replied'
console.log(type);
console.log(data);
};
}
exports.start = start;
And here is the error I get from the soap logging. Am I using the wrong name for the function?
info
Handling POST on /SayHello
info
Attempting to bind to /SayHello
info
Trying Hello_Port from path /SayHello
error
TypeError: undefined is not a function
at Server._executeMethod (C:\Users\rnewman\node_modules\soap\lib\server.js:2
41:16)
at Server._process (C:\Users\rnewman\node_modules\soap\lib\server.js:187:10)
at IncomingMessage.<anonymous> (C:\Users\rnewman\node_modules\soap\lib\serve
r.js:103:14)
at IncomingMessage.emit (events.js:92:17)
at _stream_readable.js:938:16
at process._tickCallback (node.js:419:13)
Thanks,
Robert