我正在尝试使用 SOAP Web 服务,但 WSDL 有点损坏,所以我必须对 node-soap
进行一些自定义.
我想要的理想 SOAP 信封是这个:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getImagesDefinition xmlns="http://services.example.com/"/>
</Body>
</Envelope>
到目前为止,这是 nodejs
我必须调用服务的代码:
var soap = require('soap');
var url = 'http://www.example.com/services/imagesizes?wsdl';
soap.createClient(url, function(err, client) {
client.setEndpoint('http://www.example.com/services/imagesizes');
client.getImagesDefinition(null, function(err, result) {
console.log(result);
});
console.log(client.lastRequest)
});
我不得不手动设置端点,因为它在 WSDL
中被破坏了。文件
打印时收到的信封client.lastRequest
这是:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://services.example.com/">
<soap:Body>
<getImagesDefinition />
</soap:Body>
</soap:Envelope>
我知道如果我可以强制主体上的命名空间前缀具有 <tns:getImagesDefinition />
而不是 <getImagesDefinition />
该请求完美运行。
有什么办法可以强制吗?
我读过文档说 tns
是一个默认被忽略的命名空间,所以我试图通过这样做来改变它:
var options = {
ignoredNamespaces: {
namespaces: [],
override: true
}
}
并将该对象发送到 soap.createClient
方法,但我看不出信封上有什么区别。
无论如何我可以强制这样做吗?还是找到理想的 SOAP 信封?
谢谢!
最佳答案
我遇到了这个确切的问题,对我来说,解决方法是覆盖被忽略的命名空间 - 将“tns”作为被忽略的命名空间删除。
var options = {
ignoredNamespaces: {
namespaces: ['targetNamespace', 'typedNamespace'],
override: true
}
}
我不确定为什么它对您不起作用,但也许库中存在一个已修复的错误。或者可能是因为您没有包含任何命名空间,而是包含一个空数组。
关于node.js - 如何强制使用命名空间前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27017701/