将env:mustUnderstand =“1”属性添加到使用Ruby Savon Library的SOAP请求的Header中的Security标记

时间:2011-09-07 20:44:40

标签: ruby soap savon

使用Ruby的Savon SOAP库,如何将常用的“env:mustUnderstand”属性添加到SOAP请求标头中的Security标记中?默认情况下,它不包含在标记中。

这是我目前的测试代码:

require 'rubygems'
require 'savon'

client = Savon::Client.new do
  wsdl.document = File.expand_path("../service_wsdl.xml", __FILE__)
end

client.wsse.credentials "[removed]", "[removed]"

p client.request :get_meta_data    # Server returns 500 error (presumably due to improper header)

以下是正在发送的XML(不包含mustUnderstand属性):

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:wsdl="urn:wsdl.ws.[removed].com/v1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ins0="urn:messages.ws.[removed].com/v1.1" xmlns:ins1="urn:objects.ws.[removed].com/v1.1" xmlns:ins2="urn:base.ws.[removed].com/v1.1" xmlns:ins3="urn:nullfields.ws.[removed].com/v1.1" xmlns:ins4="urn:generic.ws.[removed].com/v1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ins5="urn:metadata.ws.[removed].com/v1.1" xmlns:ins6="urn:faults.ws.[removed].com/v1.1" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
            <wsse:Username>[removed]</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">[removed]</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </env:Header>
    <env:Body>
        <GetMetaData/>
    </env:Body>
</env:Envelope>

0 个答案:

没有答案