2

我正在尝试构建一个正确的 SOAP 标头:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sen="https://webservices.averittexpress.com/SendWebImageService">
<soapenv:Header
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns:authnHeader
soapenv:mustUnderstand="0"
xmlns:ns="http://webservices.averittexpress.com/authn">
<Username>xxxxxxxx</Username> <Password>xxxxxxxx</Password>
</ns:authnHeader> </soapenv:Header>

这是我的 Savon 客户电话,我使用的是版本 2:

client = Savon.client(
  wsdl: api_url,
  raise_errors: false,
  convert_request_keys_to: :camelcase,
  element_form_default: :qualified,
  env_namespace: :soapenv,
  soap_header: {'username' => username, 'password' => password }
)

我收到以下 SOAP 错误:

fault=>
  {:faultcode=>"soapenv:Server",
  :faultstring=>"java.lang.NullPointerException",
  :detail=>nil}}

我如何得到这sapoenv:mustUserstand="0"条线,它是什么?

另外,我很困惑如何设置xmlns:ns="http://webservices.averittexpress.com/authn">.

我几乎没有使用 SOAP 请求的经验,并且来自 Ruby/Rails RESTful 背景。任何帮助,将不胜感激。

4

1 回答 1

4

Savon 使用Gyoku将 SOAP 标头和正文都转换为 XML。
遵循此库约定,您的 Hash 需要如下所示:

soap_header = {
  "ns:authnHeader" => {
    "@soapenv:mustUnderstand" => 0,
    "@xmlns:ns" => "http://webservices.averittexpress.com/authn",
    "Username"  => "x",
    "Password"  => "x"
  }
}

Savon.client(:soap_header => soap_header)
于 2013-01-15T20:50:08.443 回答