Cry*_*ICE 5 ruby wsdl web-services savon
我有一个问题,我认为是关于名称空间的问题.WSDL可以从这里下载:http://promostandards.org/content/wsdl/Order%20Shipment%20NotificationService/1.0.0/OSN-1-0-0.zip
生成请求时,它看起来像这样:
<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>
Run Code Online (Sandbox Code Playgroud)
这导致肥皂故障.
当SoapUI使用相同的WSDL构造请求时,它看起来像这样
<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>
Run Code Online (Sandbox Code Playgroud)
您可以看到SoapUI已将用户名和密码放在"shar"命名空间内.我注意到这并没有直接列在WSDL或WSDL直接加载的任何XSD文件中.它被加载类似WSDL => XSD file =>包含shar命名空间的XSD文件.这可能是问题吗?如何将命名空间添加到3个键中?我正在使用savon 2.11.1和nori 2.6.0
这是我最终使用的解决方案:
@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
})
Run Code Online (Sandbox Code Playgroud)
我认为 Savon 不会解释链接的 XSD 文件,这些文件在这里用于引用 SharedObject。有类似的问题,我找到的唯一解决方案是手动编写命名空间的定义。
在你的情况下,它可能看起来像这样:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
341 次 |
| 最近记录: |