这是我在Node.js中的服务器代码:
var soap = require('soap')
var http = require('http')
let url = 'https://test.developer.intuit.com/QBWC/TroubleshootWebServiceFS/Service.asmx?wsdl'
var express = require('express')
var bodyParser = require('body-parser')
var logger = require('morgan')
var myService = {
Hello_Service: {
Hello_Binding: {
sayHello: function(args) {
console.log(args)
return {
// I expect to see 'greeting Nick' somewhere in the response, but there is nothing
greeting: ' greeting Nick... ' //args.name
};
}
}
}
};
var xml = require('fs').readFileSync('./test_minimum.wsdl', 'utf8')
var app = express();
app.use(logger('dev'));
app.get('//', (req, res) => res.send('Hello world'))
//body parser middleware are supported (optional)
app.use(bodyParser.raw({type: function(){return true;}, limit: '5mb'}));
app.listen(8001, function(){
//Note: /wsdl route will be handled by soap module
//and all other routes & middleware will continue to work
soap.listen(app, {path: '/wsdl',
services: myService, xml: xml,
attributesKey: 'theAttrs',
valueKey: 'theVal',
xmlKey: 'theXml'});
console.log('express is listening port 8001...')
});
这是我的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://www.examples.com/SayHello/" />
</port>
</service>
</definitions>
它们的服务器正常工作,并将以下请求无错误地发送到http://localhost:8001/wsdl/
:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl">
<soap:Body/>
</soap:Envelope>
但是我没有回应“问候尼克”。没有SOAP处理程序被触发。什么地方做错了?