weixin_39816946
weixin_39816946
2020-12-01 10:04

Add wsa headers to requests automatically

Some SOAP endpoints expect the wsa headers 'wsa:Action' and 'wsa:To' to be present in every request. In the request it looks like this. Note that the 'wsa:Action' contains the request name (Echo in this case) so it is different for every request and can not be set globally.

 xml
<header xmlns:wsa="http://www.w3.org/2005/08/addressing">
 ...
  <action>http://host/Api/Echo</action>
  <to>https://host/Api.svc</to>
 ...
</header>

In SoapUI, there is a tickbox that makes it automatically add the wsa headers with all the values read from the WSDL. It would be nice to have something similar in Savon2 and enable the headers in the globals. It could look like this:

 ruby
Savon.client(default_wsa_headers: true)

Just for reference, this is how the wsa headers can be added to a request in Savon1:

 ruby
response = client.request 'Echo' do
  soap.version = 2
  soap.namespaces["xmlns:wsa"] = "http://www.w3.org/2005/08/addressing"
  soap.header = {
    "wsa:To" => "https://host/Api.svc",
    "wsa:Action" => "http://host/Api/Echo",
  }
end

And a workaround in Savon2 looks like this:

 ruby
client.globals.soap_header(
  "wsa:To" => "https://host/Api.svc",
  "wsa:Action" => "http://host/Api/Echo",
)
client.call ...

该提问来源于开源项目:savonrb/savon

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

8条回答

为你推荐

换一换