Rod*_*aki 11 soap node.js node-soap
我正在尝试使用SOAP Web服务,但是WSDL有点坏了,所以我必须做一些自定义node-soap
.
我想要的理想SOAP信封就是这个:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<getImagesDefinition xmlns="http://services.example.com/"/>
</Body>
</Envelope>
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是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)
});
Run Code Online (Sandbox Code Playgroud)
我必须手动设置端点,因为它在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>
Run Code Online (Sandbox Code Playgroud)
我知道如果我可以强制主体上的命名空间前缀<tns:getImagesDefinition />
而不是<getImagesDefinition />
请求完美地工作.
有什么办法让我强行吗?
我阅读文档说这tns
是一个默认忽略的命名空间,所以我尝试通过这样做来改变它:
var options = {
ignoredNamespaces: {
namespaces: [],
override: true
}
}
Run Code Online (Sandbox Code Playgroud)
并将该对象发送到该soap.createClient
方法,但我发现信封没有区别.
无论如何我强迫这个?或者获得理想的SOAP信封?
谢谢!
我遇到了这个确切的问题,对我来说,修复方法是覆盖忽略的命名空间 - 将“tns”作为忽略的命名空间删除。
var options = {
ignoredNamespaces: {
namespaces: ['targetNamespace', 'typedNamespace'],
override: true
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么它对你不起作用,但也许库中有一个错误已经被修复。或者可能是因为您没有包含任何名称空间,而是包含一个空数组。
请参阅github 上讨论同一问题的线程:
特别是 https://github.com/vpulim/node-soap/issues/537#issuecomment-72041420