setting session ID in the soap header

633 views
Skip to first unread message

ami.g...@gmail.com

unread,
May 9, 2005, 3:07:55 AM5/9/05
to soa...@googlegroups.com
Hi All,

I'm trying to use the Salesforce.com SOAP API. The login call returns
a session ID that should be set in the SOAP header of subsequent calls.
After much searching, I found an example of how to do this, but it
doesn't seem to work - I assume the soap4r api has changed since the
example was written.

Can anybody provide a short description of how this is done?

I know about ClientAuthHeaderHandler, but I can't figure out how it's
supposed to be used.

Regards, and thanks in advance for any help,

Ami.

ami.g...@gmail.com

unread,
May 9, 2005, 6:28:03 AM5/9/05
to soa...@googlegroups.com
Ok, I've made some progress. I've managed to add a field to the header
by modifying an example I found elsewhere:

-----

class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler
MyHeaderName = XSD::QName.new("urn:partner.soap.sforce.com",
"sessionId")

attr_accessor :sessionid

def initialize
super(MyHeaderName)
@sessionid = nil
end

def on_simple_outbound
if @sessionid
{ "sessionid" => @sessionid }
end
end

def on_simple_inbound(my_header, mustunderstand)
@sessionid = my_header["sessionid"]
end
end

----

It still doesn't work (invalid session id), possibly because the
request should resemble this (from the Salesforce.com documentation):
<ns2:sessionId

xmlns:ns2="urn:enterprise.soap.sforce.com">uejMEgecf8yidA3zCjXlNKOSU</
ns2:sessionId>

but I'm producing this:
<sessionid>vWBLOmDK9MI6Xv9U4eTDteaH1xyGi1</sessionid>

I figure I have to use "XSD::QName.new" somewhere, but everywhere I've
tried gives incorrect results (and I obviously don't understand how
these classes are used).

Help?

... Ami.

NAKAMURA, Hiroshi

unread,
May 9, 2005, 12:27:45 PM5/9/05
to soa...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Sorry for late reply.
Hmm. Is this a typo, 'sessionid', not 'sessionId' ? session*I*d.

According to the above example, I think this should work.

def on_simple_outbound
if @sessionid
{ XSD::QName.new("urn:enterprise.soap.sforce.com",
"sessionId") => @sessionid }
end
end

But the only WSDL I know is partner.wsdl, which does not define
'urn:enterprise.soap.sforce.com'. I can be wrong...

Regards,
// NaHi
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)

iD8DBQFCf4+Bf6b33ts2dPkRAnWFAJwPNbKTyRy1meT7VgjZvYDI59CbiwCglNAY
YYplD+kQEQ+flRlfO7UldXM=
=V//d
-----END PGP SIGNATURE-----

ami.g...@gmail.com

unread,
May 10, 2005, 3:10:07 AM5/10/05
to soa...@googlegroups.com
It worked! Thanks a million!

There were a number of problems with the code I posted earlier,
including the case of off sessionId. I had figured those out, but I
still needed your little snippet to put the rest together. I'm using
the partner WSDL, although the example I had cut from the documentation
uses the enterprise WSDL. I think they're the same except the
enterprise WSDL is more strongly typed.

By the way, I had tried earlier to import the WSDL, but it I kept
getting errors (I can't remember exactly, something about nil values I
think). If you think this should work I can try again and post the
results.

Regards,
Ami.

NAKAMURA, Hiroshi

unread,
May 10, 2005, 5:01:15 AM5/10/05
to soa...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

ami.g...@gmail.com wrote:
> It worked! Thanks a million!

Good to hear.

> By the way, I had tried earlier to import the WSDL, but it I kept
> getting errors (I can't remember exactly, something about nil values I
> think). If you think this should work I can try again and post the
> results.

Thanks in advance. Please show me the results. Early snapshot versions
have many problems about parsing full(?) featured XML Schema definition
(+WSDL). I wrote many code in this half of a year but test is still not
enough.

Regards,
// NaHi
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)

iD8DBQFCgHhbf6b33ts2dPkRAjElAKDGqST511EoWDemEh2sNBLUSkgt+gCfd4PB
V6S2RLvgDGn9kb5HgpjPrWY=
=Eobk
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages