[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Add namespace to the SOAP Body and Header

NAKAMURA, Hiroshi

6/5/2007 4:33:00 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

David Alphen wrote:
> So I need several things:
>
> _add namespaces to the Header and Body tags,
> _plus the Header tag is empty, it does not contain any element (I have seen
> lots of example that add element to the header but not just an empty
> header):
>
> <soap:Header xmlns="http://webservices.amadeus.com/d...
> "></soap:Header>

Following code samples require soap4r-1.5.6 RC2. You need to get 1.5.6
RC2 from http://dev.ctor.org/soap4r/wiki#a2007-06-05...

1. empty SOAP Header

soap4r-1.5.5 cannot send empty SOAPHeader. With 1.5.6, you can do that
like this;

require 'soap/rpc/driver'
require 'soap/header/handler'

class EmptyHeaderHandler < SOAP::Header::Handler
def on_outbound(header)
# dump SOAPHeader even if it has no item
header.force_encode = true
header.extraattr['xmlns'] = 'urn:foo'
# no item needed
nil
end
end

driver = SOAP::RPC::Driver.new('http://localhost:7171/soapendpoint')
driver.wiredump_dev = STDOUT
driver.headerhandler << EmptyHeaderHandler.new(XSD::QName::EMPTY)
driver.add_method('nop').call


2. free namespace definition control

At first, XML processors must handle both A and B as the same.

A. <env:Body>
<n1:Air_MultiAvailability xmlns:n1="http://my.url.com/SAR_07&...
</env:Body>
B. <env:Body xmlns="http://my.url.com/SAR_07...
<Air_MultiAvailability/>
</env:Body>

But I can understand that there's a case we cannot change other party's
SOAP implementation. For the case of this, you need to construct XML by
yourself like this;

driver = SOAP::RPC::Driver.new('http://localhost:7171/soapendpoint')
header = SOAP::SOAPHeader.new
header.extraattr['xmlns'] = 'urn:foo'
header.force_encode = true
require 'rexml/document'
body = SOAP::SOAPBody.new(
REXML::Document.new('<Air_MultiAvailability/>'))
body.extraattr['xmlns'] = 'urn:foo'
driver.invoke(header, body)

Of course you'd better to ask the other party to fix the implementation.

Regards,
// NaHi

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iQEVAwUBRmTnUh9L2jg5EEGlAQKpgAf9F4o7yMwFp0OGRp9clEupC/ex5Fphejyv
uatlBb2nH/4ZoBl4ufZQdhrYNYics2E9TZ+TmdZujCfV/v8kgxAPys1OWYh2enQB
va6ayndvcD+bTDG7fRdoQQmOW+ZYDePRm814pCcuqZEYwOxTjYEilHTBY+cw/sdU
w5qIKc8B5lh6OXcbUF3ezWY/XGChrNK6flGKRzuRt8zrDFgIsyf2F75QkH8DXxrR
4yS1lTQ4AHWrpqBrH2EnWjJmILCCw8ZqBzaXC4XfYOizmBxrsyhx9tULQkClD2tR
ai5iky6cx9nUuPcu2oaiZryDQ02dt7gx8W1fwfrnwzyk3BFS+6ps+w==
=ree6
-----END PGP SIGNATURE-----