【问题标题】:Having issue while using soap4r, unable to add namespace, encoding style to soap envelope使用soap4r时出现问题,无法将命名空间、编码样式添加到soap信封
【发布时间】:2011-01-21 22:52:42
【问题描述】:

我正在使用的一种肥皂服务出现问题。我正在使用 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>
不返回所需的输出。他们期待的是:
USER_NAME用户名>
          API_KEY认证>
        身份证完成操作>
              名称>
            
          
        正文>
命名空间和根中的编码样式(因为他们在标头 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)

【问题讨论】:

    标签: ruby soap wsdl soap4r


    【解决方案1】:

    强烈建议您不要在soap4r 上浪费太多时间。

    如果它有效,那就太好了。但是,如果您的 SOAP 服务有特定的期望或以某种方式被破坏,那么它绝对是无用的(如果没有大量的猴子补丁就不可能修复)。库的内部状态也很糟糕,它在 Ruby 1.9 中不起作用。

    对于 SOAP 接口,我已经开始使用 handsoap,它允许您手动构建 SOAP 消息,这正是您的服务所期望的。这是一个多一点的工作,但它为我节省了很多与你类似的头痛。它也适用于 Ruby 1.9。我没有回头。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多