ruby savon 和 wsdl 命名空间 [英] ruby savon and wsdl namespacing
问题描述
我认为有一个与命名空间有关的问题.WSDL 可以从这里下载:http://promostandards.org/content/wsdl/Order%20Shipment%20NotificationService/1.0.0/OSN-1-0-0.zip
I have an issue that I believe is in regards to namespaces. The WSDL can be downloaded from here: http://promostandards.org/content/wsdl/Order%20Shipment%20NotificationService/1.0.0/OSN-1-0-0.zip
当请求生成时,它看起来像这样:
When the request is generated it looks like this:
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.promostandards.org/WSDL/OrderShipmentNotificationService/1.0.0/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:GetOrderShipmentNotificationRequest>
<tns:wsVersion>1.0.0</tns:wsVersion>
<tns:id>myusername</tns:id>
<tns:password>mypassword</tns:password>
<tns:queryType>3</tns:queryType>
<tns:shipmentDateTimeStamp>2017-07-19</tns:shipmentDateTimeStamp>
</tns:GetOrderShipmentNotificationRequest>
</soapenv:Body>
</soapenv:Envelope>
这会导致肥皂故障.
当 SoapUI 使用相同的 WSDL 构造请求时,它看起来像这样
When SoapUI constructs the request using the same WSDL it looks like this
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.promostandards.org/WSDL/OrderShipmentNotificationService/1.0.0/" xmlns:shar="http://www.promostandards.org/WSDL/OrderShipmentNotificationService/1.0.0/SharedObjects/">
<soapenv:Header/>
<soapenv:Body>
<ns:GetOrderShipmentNotificationRequest>
<shar:wsVersion>1.0.0</shar:wsVersion>
<shar:id>myusername</shar:id>
<shar:password>mypassword</shar:password>
<ns:queryType>3</ns:queryType>
<ns:shipmentDateTimeStamp>2017-07-19</ns:shipmentDateTimeStamp>
</ns:GetOrderShipmentNotificationRequest>
</soapenv:Body>
</soapenv:Envelope>
您可以看到 SoapUI 已将用户名和密码放置在shar"命名空间中.我注意到这没有直接列在 WSDL 或由 WSDL 直接加载的任何 XSD 文件中.它被加载类似于 WSDL => XSD 文件 => 包含 shar 命名空间的 XSD 文件.这可能是问题吗?如何将命名空间添加到仅 3 个键?我使用的是 savon 2.11.1 和 nori 2.6.0
You can see that SoapUI has placed the username and password inside the "shar" namespace. I noticed that this is not directly listed in the WSDL or in any XSD file directly loaded by the WSDL. It gets loaded something like WSDL => XSD file => XSD file containing shar namespace. could that be the issue? How can I add the namespace to just 3 of the keys? I'm using savon 2.11.1 and nori 2.6.0
这是我最终使用的解决方案:
Here is the solution I ended up using:
@client = Savon.client(
wsdl: 'OSN-1-0-0/WSDL/1.0.0/OrderShipmentNotificationService.wsdl',
endpoint: @endpoint,
env_namespace: :soapenv,
namespaces: { "xmlns:shar" => "http://www.promostandards.org/WSDL/OrderShipmentNotificationService/1.0.0/SharedObjects/" },
element_form_default: :qualified,
headers: { "accept-encoding" => "identity" }
)
response = @client.call(:get_order_shipment_notification, message: {
'shar:ws_version': @version,
'shar:id': @username,
'shar:password': @password,
query_type: 3,
shipment_date_time_stamp: date
})
推荐答案
我认为 Savon 不会解释链接的 XSD 文件,这里使用这些文件来引用 SharedObject.遇到了类似的问题,我找到的唯一解决方案是手动编写命名空间的定义.
I think Savon doesn't interpret linked XSD files, which are used here to reference the SharedObject. Had a similar problem and the only solution I found was to manually write the definition of the namespaces.
在您的情况下,它可能看起来像这样:
In your case it might look something like this:
client = Savon.client do
endpoint "http://localhost/OrderShipmentNotificationService.svc"
element_form_default :qualified
namespace "http://www.promostandards.org/WSDL/OrderShipmentNotificationService/1.0.0/"
namespace_identifier :ns
namespaces "xmlns:shar"=>"http://www.promostandards.org/WSDL/OrderShipmentNotificationService/1.0.0/SharedObjects/"
end
response = client.call("GetOrderShipmentNotificationRequest") do |locals|
locals.message "shar:wsVersion"=>"1.0.0","shar:id"=>"myusername",...
end
这篇关于ruby savon 和 wsdl 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!