用Savon宝石修改SOAP XML命名空间

4

我试图修改Savon SOAP调用中的一个命名空间。以下是我的请求示例:

HTTPI GET request to www.intg.pathway.verosapps.com (excon)
SOAP request: https://www.intg.pathway.verosapps.com/VerosPathway.svc
SOAPAction: "urn:IVerosPathway/VerosPathway_Ping", Content-Type: text/xml;charset=UTF-8, Content-Length: 434
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <VerosPathway_Ping>
      <request>
        <Credentials>
          <UserId>*username*</UserId>
          <Password>*password*</Password>
        </Credentials>
      </request>
    </VerosPathway_Ping>
  </soapenv:Body>
</soapenv:Envelope>

由于这家公司期望客户使用.NET进行SOAP交互,而我们正在使用Ruby,因此我不得不进行大量调整。我非常接近正确的格式,但在信封部分需要执行以下两个操作之一:

  1. 将“xmlns =“http://tempuri.org/””更改为“xmlns:wsdl =“http://tempuri.org/””
  2. 或者完全删除“xmlns =“http://tempuri.org/””

这是我的Savon调用:

apiClient = Savon.client(endpoint: "https://www.intg.pathway.verosapps.com/VerosPathway.svc", env_namespace: :soapenv, namespace_identifier: nil, logger: Rails.logger, log_level: :debug, log: true, :pretty_print_xml => true, ssl_version: :TLSv1, wsdl: 'https://www.intg.pathway.verosapps.com/VerosPathway.svc?wsdl')

如果我在Savon调用中添加以下行:
namespaces: {"xmlns:wsdl" => "http://tempuri.org/"}

那么我的请求看起来像这样:

然后我的请求是这样的:

HTTPI GET request to www.intg.pathway.verosapps.com (excon)
    SOAP request: https://www.intg.pathway.verosapps.com/VerosPathway.svc
    SOAPAction: "urn:IVerosPathway/VerosPathway_Ping", Content-Type: text/xml;charset=UTF-8, Content-Length: 434
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://tempuri.org/">
      <soapenv:Body>
        <VerosPathway_Ping>
          <request>
            <Credentials>
              <UserId>*username*</UserId>
              <Password>*password*</Password>
            </Credentials>
          </request>
        </VerosPathway_Ping>
      </soapenv:Body>
    </soapenv:Envelope>

在这种情况下,我只需要删除“xmlns =“http://tempuri.org/””这一行即可。
非常感谢您的建议。
谢谢!
2个回答

5
您可以按照以下选项简单地传递哈希:
client = Savon.client(
     wsdl: "https://example.com?wsdl",
     log: true,
     log_level: :debug,
     pretty_print_xml: true,
     namespace_identifier: :mes,
     namespaces: {"xmlns:mes" => "http://example.com/messages/","xmlns:glob"=>"http://example.com/globals"}                      
) 

4
我终于想通了,只需要在我的Savon调用中添加以下行即可:
namespace: ""

所以我的最终Savon调用如下:
apiClient = Savon.client(
    endpoint: "https://www.intg.pathway.verosapps.com/VerosPathway.svc",
    namespace: "", 
    env_namespace: :soapenv, 
    namespace_identifier: nil, 
    logger: Rails.logger, 
    log_level: :debug, 
    log: true, 
    :pretty_print_xml => true, 
    ssl_version: :TLSv1, 
    wsdl: 'https://www.intg.pathway.verosapps.com/VerosPathway.svc?wsdl'
)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接