我正在尝试使用Savon(版本2)构建SOAP请求。
这是请求XML的外观:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<cred_LogIn xmlns="http://webservice.dz-manager.com/">
<sUsername>string</sUsername>
<sPassword>string</sPassword>
<sConsumerIdent>string</sConsumerIdent>
</cred_LogIn>
</soap12:Body>
</soap12:Envelope>
当我这样做时:
client = Savon.client(
wsdl: 'https://online-tools.dz-manager.com/Services/DzM_WebService.asmx?WSDL',
soap_version: 2,
pretty_print_xml: true,
env_namespace: 'soap12',
namespace_identifier: nil,
log_level: :debug)
client.call(:cred_log_in,
message:
{username: 'my_username',
password: 'my_password',
consumer_ident: 'DZ-Manager_Web-Service_Consumer'},
attributes: {
xmlns: 'http://webservice.dz-manager.com/'}
)
Savon构建以下XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://webservice.dz-manager.com/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<cred_LogIn xmlns="http://webservice.dz-manager.com/">
<username>my_username</username>
<password>my_password</password>
<consumerIdent>DZ-Manager_Web-Service_Consumer</consumerIdent>
</cred_LogIn>
</soap12:Body>
</soap12:Envelope>
这几乎是期望的结果。唯一的区别是消息元素应以's'开头,例如:<username>
应当为<sUsername>
。我在其他操作中发现“ int”(即整数)和“ l”(即long)时,此“ s”可能表示“字符串”。
在Savon中,是否有隐藏的选项可以在消息元素之前附加其数据类型?如果不是,如何确定元素的数据类型缩写呢?
更改值中的键message
不起作用:s_username: 'my-username'
of 'sUsername' => 'my-username'
。
class ServiceRequest
def to_s
builder = Builder::XmlMarkup.new
builder.tag! :sUsername, "my_username"
builder.tag! :sPassword, "my_password"
builder.tag! :sConsumerIdent, "DZ-Manager_Web-Service_Consumer"
builder
end
end
然后在终端中:
client = Savon.client(
wsdl: 'https://online-tools.dz-manager.com/Services/DzM_WebService.asmx?WSDL',
soap_version: 2,
pretty_print_xml: true,
env_namespace: 'soap12',
namespace_identifier: nil,
log_level: :debug)
client.call(:cred_log_in,
message: ServiceRequest.new,
attributes: {
xmlns: 'http://webservice.dz-manager.com/'}
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句