我正在使用的一种肥皂服务出现问题。我soap4r
用于消费肥皂服务。但不知何故,他们期待的不是我发送的东西。这就是我要发送的内容:
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<authenticate env:mustUnderstand="0">
<username>USERNAME</username>
<apiKey>API_KEY</apiKey>
</authenticate>
<SoftLayer_Network_Media_Transcode_AccountInitParameters env:mustUnderstand="0">
<id>ID</id>
</SoftLayer_Network_Media_Transcode_AccountInitParameters>
<SoftLayer_Network_Media_Transcode_AccountObjectFilter env:mustUnderstand="0">
<transcodeJobs>
<transcodeStatus>
<name>
<operation>Complete</operation>
</name>
</transcodeStatus>
</transcodeJobs>
</SoftLayer_Network_Media_Transcode_AccountObjectFilter>
</env:Header>
<env:Body>
<n1:getTranscodeJobs xmlns:n1="http://api.service.softlayer.com/soap/v3/"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
</n1:getTranscodeJobs>
</env:Body>
</env:Envelope>
这不会返回所需的输出。他们期待的是:<?xml 版本="1.0" 编码="utf-8" ?> <env:信封 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="http://api.service.softlayer.com/soap/v3/" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <环境:标题> <authenticate env:mustUnderstand="0"> <用户名>USER_NAME</用户名> <apiKey>API_KEY</apiKey> </认证> <SoftLayer_Network_Media_Transcode_AccountInitParameters 环境:mustUnderstand="0"> <id>身份证</id> </SoftLayer_Network_Media_Transcode_AccountInitParameters> <n1:SoftLayer_Network_Media_Transcode_AccountObjectFilter 环境:mustUnderstand="0"> <转码作业> <转码状态> <名称> <操作>完成</操作> </名称> </transcodeStatus> </transcodeJobs> </n1:SoftLayer_Network_Media_Transcode_AccountObjectFilter> </env:Header> <环境:正文> <n1:getTranscodeJobs > </n1:getTranscodeJobs> </env:正文> </env:信封>根中的命名空间和编码样式(因为他们在标头 ObjectFilter 中使用它)。soap4r 正在生成前一个请求,我无法将其更改为实际有效的后一个请求。
这是我使用soap4r的方式:
class SLHeader < SOAP::Header::SimpleHandler
def initialize(tag, out)
@out = out
super(XSD::QName.new(nil, tag))
end
def on_simple_outbound
@out
end
end
SOAP_WSDL_ENDPOINT = "endpoint"
service = "service name"
initParams = {'id' => ID}
objectFilter = {'transcodeJobs' => {'transcodeStatus' => {'name' => {'operation' => STATUS}}}}
driver = SOAP::WSDLDriverFactory.new(SOAP_WSDL_ENDPOINT + service + "?wsdl").create_rpc_driver
driver.headerhandler << SLHeader.new('authenticate', {'username' => @auth_user, 'apiKey' => @auth_key})
driver.headerhandler << SLHeader.new(service + 'InitParameters', initParam)
driver.headerhandler << SLHeader.new(service + 'ObjectFilter', objectFilter)