Adding a header to a SOAP request

D

David Teare

Hi all,

I want to use ruby to integrate my site with PayPal's new Website
Direct Pro API. I tried the code below, and it seems to work once I
upgraded to soap4r-1_5_4:

require 'soap/wsdlDriver'
server = SOAP::WSDLDriverFactory.new("http://
www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl")
@driver = server.createDriver

One problem I'm having is Paypal requires that I set a header in the
request (user id & password). How do I add this before performing a
request?

Any help or pointers to some SOAP/WSDL ruby documentation would be
greatly appreciated.

Thanks!
--Dave.
 
P

Patrick Chanezon

something like that works: that's what I use for the Google Adwords API.
The soap4r sample for adwords has a bug, but the code below works.
Just adapt it to your needs for the paypal headers.
In my code headers is a hash with tag, value pairs.
I load it from a yaml file but you can set it up the way you want.
I hope this helps.

---
wsdl =3D 'https://adwords.google.com/api/adwords/v2/CampaignService?WSDL'

class HeaderHandler < SOAP::Header::SimpleHandler
def initialize(tag, value)
super(XSD::QName.new(nil, tag))
@tag =3D tag
@value =3D value
end

#the initial handler from the sample was wrong, it generated 2 level of tag=
s
def on_simple_outbound
@value
end
end

require 'defaultDriver.rb'
require 'yaml'

prefs =3D YAML::load( File.open('adwords.yaml', 'r'))
headers =3D prefs['headers']

drv =3D CampaignService.new()

#problem: http protocol properties set in soap/property from rubyhome
are not picked up
drv.loadproperty('soap/property')
#problem: wiredump_dev does not output anything when running in SSL mode
#drv.wiredump_dev =3D STDOUT
#the file based logger works
drv.wiredump_file_base =3D "log"

headers.each {|key, value| drv.headerhandler << HeaderHandler.new(key, valu=
e)}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top