红宝石savon和wsdl命名空间
问题描述:
我有一个问题,我相信是关于命名空间。该WSDL可从这里下载:http://promostandards.org/content/wsdl/Order%20Shipment%20NotificationService/1.0.0/OSN-1-0-0.zip红宝石savon和wsdl命名空间
当产生请求时,它看起来是这样的:
<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>
这将导致一个SOAP错误。
当了SoapUI构建使用它看起来像这样
<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>
同一个WSDL可以看到了SoapUI已经把用户名和密码的“沙皮”命名空间里的请求。我注意到这并不是直接列在WSDL中,或者直接由WSDL加载的任何XSD文件中。它得到加载类似于WSDL => XSD文件=>包含shar命名空间的XSD文件。这可能是问题吗?我怎样才能将命名空间添加到3个键?我正在使用savon 2.11.1和nori 2.6.0
答
我想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