如何强制 Savon 使用特定的参数大小写
How to force Savon to use a specific parameter case
我正在尝试使用 Savon 连接到 SOAP API。
WSDL 显示如下:
wsdl:operation name="CustomerList" parameterOrder="Username Password Settings">
<wsdl:input message="impl:CustomerListRequest" name="CustomerListRequest"/>
<wsdl:output message="impl:CustomerListResponse" name="CustomerListResponse"/>
</wsdl:operation>
客户支持说使用这样的请求:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ei2="http://ei2.nobj.nable.com/">
<soap:Header/>
<soap:Body>
<ei2:customerList>
<!--Optional:-->
<ei2:username>testaccount@n-able.com</ei2:username>
<!--Optional:-->
<ei2:password>!PDf2lfij23l!!</ei2:password>
<!--Zero or more repetitions:-->
<ei2:settings>
<!--Optional:-->
<ei2:key>null</ei2:key>
<!--Optional:-->
<ei2:value>null</ei2:value>
</ei2:settings>
</ei2:customerList>
</soap:Body>
</soap:Envelope>
这是我的要求:
{"SOAPAction"=>"\"CustomerList\"", "Content-Type"=>"text/xml;charset=UTF-8", "Content-Length"=>"452"}
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://www.n-able.com/mickey" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<impl:CustomerList>
<username>test@test.com</username>
<password>MytestPassword1234</password>
<settings>
<listSOs>false</listSOs>
</settings>
</impl:CustomerList>
</env:Body>
</env:Envelope>
不同之处在于 Savon 使用并生成调用方法的 WSDL 使我的请求发送 CustomerList
而不是 API 似乎期望的 customerList
.
有没有办法在不手动构建整个 SOAP 请求的情况下强制 Savon 发送 CustomerList
而不是 customerList
?
编辑 1
在这个 Github 问题中找到了答案。 https://github.com/savonrb/savon/issues/530
通过将以下内容添加到 gemspec,我能够获得格式正确的请求:
spec.add_runtime_dependency 'savon', '~> 2.3'
spec.add_runtime_dependency 'wasabi', '~> 3.2'
在构建客户端时包括其中之一:
convert_request_keys_to :camelcase # or one of [:lower_camelcase, :upcase, :none]
或者在没有 WSDL 的情况下工作并使用 'strings' 手动编码调用。
我正在尝试使用 Savon 连接到 SOAP API。
WSDL 显示如下:
wsdl:operation name="CustomerList" parameterOrder="Username Password Settings">
<wsdl:input message="impl:CustomerListRequest" name="CustomerListRequest"/>
<wsdl:output message="impl:CustomerListResponse" name="CustomerListResponse"/>
</wsdl:operation>
客户支持说使用这样的请求:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ei2="http://ei2.nobj.nable.com/">
<soap:Header/>
<soap:Body>
<ei2:customerList>
<!--Optional:-->
<ei2:username>testaccount@n-able.com</ei2:username>
<!--Optional:-->
<ei2:password>!PDf2lfij23l!!</ei2:password>
<!--Zero or more repetitions:-->
<ei2:settings>
<!--Optional:-->
<ei2:key>null</ei2:key>
<!--Optional:-->
<ei2:value>null</ei2:value>
</ei2:settings>
</ei2:customerList>
</soap:Body>
</soap:Envelope>
这是我的要求:
{"SOAPAction"=>"\"CustomerList\"", "Content-Type"=>"text/xml;charset=UTF-8", "Content-Length"=>"452"}
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://www.n-able.com/mickey" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<impl:CustomerList>
<username>test@test.com</username>
<password>MytestPassword1234</password>
<settings>
<listSOs>false</listSOs>
</settings>
</impl:CustomerList>
</env:Body>
</env:Envelope>
不同之处在于 Savon 使用并生成调用方法的 WSDL 使我的请求发送 CustomerList
而不是 API 似乎期望的 customerList
.
有没有办法在不手动构建整个 SOAP 请求的情况下强制 Savon 发送 CustomerList
而不是 customerList
?
编辑 1 在这个 Github 问题中找到了答案。 https://github.com/savonrb/savon/issues/530
通过将以下内容添加到 gemspec,我能够获得格式正确的请求:
spec.add_runtime_dependency 'savon', '~> 2.3'
spec.add_runtime_dependency 'wasabi', '~> 3.2'
在构建客户端时包括其中之一:
convert_request_keys_to :camelcase # or one of [:lower_camelcase, :upcase, :none]
或者在没有 WSDL 的情况下工作并使用 'strings' 手动编码调用。