使用 Savon gem 修改 SOAP XML 命名空间
Modifying SOAP XML namespace with Savon gem
我正在尝试修改我的 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。我非常接近正确的格式,但我需要在信封部分做两件事之一:
- 将 "xmlns="http://tempuri.org/" 更改为 "xmlns:wsdl="http://tempuri.org/"
- 或 完全删除 "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/" 行。
如有任何建议,我们将不胜感激。
谢谢!
我终于明白了。我需要做的就是将以下行添加到我的 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'
)
您可以简单地使用以下选项传递哈希:
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"}
)
我正在尝试修改我的 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。我非常接近正确的格式,但我需要在信封部分做两件事之一:
- 将 "xmlns="http://tempuri.org/" 更改为 "xmlns:wsdl="http://tempuri.org/"
- 或 完全删除 "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/" 行。
如有任何建议,我们将不胜感激。
谢谢!
我终于明白了。我需要做的就是将以下行添加到我的 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'
)
您可以简单地使用以下选项传递哈希:
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"}
)