我如何强制命名空间前缀使用?

我想消费一个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信封?

谢谢!

我遇到了这个确切的问题,对我来说,修复是重写ignorednamespaces – 删除“tns”作为一个被忽略的命名空间。

 var options = { ignoredNamespaces: { namespaces: ['targetNamespace', 'typedNamespace'], override: true } } 

我不知道为什么它不适合你,但也许在图书馆有一个错误已经修复。 或者也许是因为你没有包含任何命名空间,而是一个空的数组。

在github上讨论相同的问题:

特别是https://github.com/vpulim/node-soap/issues/537#issuecomment-72041420

Interesting Posts