Help on customizing request header for MS AdCenter API

6 views
Skip to first unread message

jfcouture

unread,
Aug 9, 2007, 5:25:32 PM8/9/07
to soap4r
Hi,

I'm using Soap4r to connect to the microsoft adcenter api.

Right now, the sent soap message looks like this:

<?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>
<n1:ApiUserAuthHeader xmlns:n1="http://adcenter.microsoft.com/
syncapis" env:mustUnderstand="0">
<UserName>x</UserName>
<UserAccessKey>x</UserAccessKey>
<Password>x</Password>
</n1:ApiUserAuthHeader>
</env:Header>
<env:Body>
<n2:GetQuota xmlns:n2="http://adcenter.microsoft.com/syncapis">
<n2:APIFlags>0</n2:APIFlags>
</n2:GetQuota>
</env:Body>
</env:Envelope>


This results in unauthorized access error.
Using a script found in this thread
http://groups.google.com/group/soap4r/browse_thread/thread/2c6204faf0450b29
I have been able to find that removing the n1 namespace works:

<?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>
<ApiUserAuthHeader xmlns="http://adcenter.microsoft.com/syncapis">
<UserName>x</UserName>
<UserAccessKey>x</UserAccessKey>
<Password>x</Password>
</ApiUserAuthHeader>
</env:Header>
<env:Body>
<n2:GetQuota xmlns:n2="http://adcenter.microsoft.com/syncapis">
<n2:APIFlags>0</n2:APIFlags>
</n2:GetQuota>
</env:Body>
</env:Envelope>

This requests works.

How can I get soap4r to generate a soap request that will look like
this one?

I'm using this to generate the header:

class CustomSimpleHeader < SOAP::Header::SimpleHandler
# encapsulate outbound only headers, this is set once and never
# touched again.
#
def initialize(itemname,namespace,childdata)
super(XSD::QName.new(namespace,itemname))

case childdata
# other classes if you want
# Or do something with XML::Mappging
when Hash
xml = StringIO.new
childdata.each_pair do |key,value|
xml.puts("<#{key}>#{value}</#{key}>")
end
@item = xml.string
else
@item = childdata.to_s
end
end

def on_simple_outbound
@item if @item
end

def on_simple_inbound
end
end

client.headerhandler << CustomSimpleHeader.new("ApiUserAuthHeader",
"http://adcenter.microsoft.com/syncapis",
{ "UserName" => 'x',
"Password" => 'x',
"UserAccessKey" => 'x'})


Thanks

Jean-Francois Couture

Herryanto Siatono

unread,
Aug 9, 2007, 9:49:37 PM8/9/07
to soa...@googlegroups.com
Hi Jean,

Looks similar to the problem I was facing the other day.

Try to setting elementformdefault option to true, when calling
add_[rpc|document]_operation

I used wsdl2ruby to generate my RPC::Driver, after that I put a short plug
to enable that option in init_methods, something like this:

[ServiceName|'default']Driver.rb
-------------------------------

def init_methods
Methods.each do |definitions|
# set options to use default namespace instead of using n[#]
opt = definitions.last
opt.merge!({
:elementformdefault => true,
:attributeformdefault => true
})

# rest of the codes generated by wsdl2ruby
if opt[:request_style] == :document
add_document_operation(*definitions)
else
add_rpc_operation(*definitions)

....
end
end
end

http://groups.google.com/group/soap4r/browse_thread/thread/cba0b96b93373e10/
c569ff298dc8fe8b?lnk=gst&q=herryanto&rnum=1#c569ff298dc8fe8b

Hope it helps.

Herry

jfcouture

unread,
Aug 10, 2007, 8:57:49 AM8/10/07
to soap4r
Thanks, that worked perfectly!

Jean-Francois Couture

> http://groups.google.com/group/soap4r/browse_thread/thread/cba0b96b93...

> Using a script found in this threadhttp://groups.google.com/group/soap4r/browse_thread/thread/2c6204faf0...

NAKAMURA, Hiroshi

unread,
Aug 16, 2007, 8:08:44 AM8/16/07
to soa...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Herryanto Siatono wrote:
> Try to setting elementformdefault option to true, when calling
> add_[rpc|document]_operation

Thanks for the tip.

I also saw the post at
http://www.pluitsolutions.com/2007/08/10/remove-n1-namespace-for-soap4r/.
Would you please show me the WSDL you utilized to generate stub files?
Possibly soap4r fails to parse 'elementFormDefault' definition in WSDL
file. Adding a :elementformdefault definition should be done by soap4r.

Regards,
// NaHi

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

iQEVAwUBRsQ+Sh9L2jg5EEGlAQLGhQgAu3zYU+3u6o29F4JujnJcWQkXKUewVV13
PFKYlpqxAy+d0TQx/TZ8R8yZUh6TD3jjaNauua1sUrU2wb5DyXUlI25j3SW0BUks
Ea/AR+M0kxeqIS9j+WNpvq1wQbd9pVAXGjPzW1pULa3iKHHf6OhIm9yYXej5r9bL
toRSe33iyhQHATFFYdaab9FyZ5v9tzl54/zOMto3qoOuqX48+TfzMjdheXVbCJL9
LBYqTyKnFcCPi5JBTLMV+zz3aBo7TSp+69czjI/F9INGh3CkiEjwZkItaXpuV54L
xsfZCxjk6EpzggFxx8Z2Mp/P3nBx6Mq7iOq/FWPGMNVMLAd6b/IZeg==
=XQfI
-----END PGP SIGNATURE-----

Reply all
Reply to author
Forward
0 new messages