我尝试使用Node Js和node-soap实现一个简单的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>
server.js
var soap = require('soap');
var http = require('http');
var service = {
ws: {
calc: {
sumar : function(args) {
var n = args.a + args.b;
return { res : n };
},
multiplicar : function(args) {
var n = args.a * args.b;
return { res : n }
}
}
}
}
var xml = require('fs').readFileSync('wscalc1.wsdl', 'utf8'),
server = http.createServer(function(request,response) {
response.end("404: Not Found: "+request.url)
});
server.listen(8000);
soap.listen(server, '/wscalc1', service, xml);
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
任何帮助都将不胜感激
2条答案
按热度按时间vbopmzt11#
正如user 672320所指出的,client.js失败的原因是因为所使用的wsdl的格式是“RPC/literal”,但样式被设置为“document”而不是RPC。
事实上,五种格式中的任何一种都可以用于WSDL,每种格式都有不同的格式。
请参阅Which style of WSDL should I use?以取得有关使用哪种型式的讨论。
此外,给出的示例并不完整。
扩展版本见下文:
wsdl文件:
server.js:
client.js:
代码输出为:
ckocjqey2#
在wsdl文件中,我改变的是从文档到rpc的样式,试图使用client.js获得其他响应
我收到的是这个输出。