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

生成请求后如下所示:

<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 使用相同的 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>

可以看到SoapUI已经把用户名和密码放到了"shar"命名空间里面。我注意到这没有直接列在 WSDL 中,也没有列在由 WSDL 直接加载的任何 XSD 文件中。它会加载类似 WSDL => XSD 文件 => XSD 包含 shar 命名空间的文件。这可能是问题所在吗?如何将名称空间添加到其中的 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
})

我认为 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