Difference between revisions of "ZSI Examples - 002"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: <pre> All.. I'm using stubs generated from the latest (as of yesterday) ZSI trunk. I need to be able to pass in credentials (user, pass, app name) thru the SOAP headers, so I am passing ...)
 
Line 115: Line 115:


See:
See:
* [http://esbinfo:8090/download/attachments/5998643/SessionService_server.py]
* http://www.performiq.com.au/kb/images/SessionService_types.py
* [http://esbinfo:8090/download/attachments/5998643/SessionService_client.py]
* http://www.performiq.com.au/kb/images/SessionService_client.py]
* [http://esbinfo:8090/download/attachments/5998643/SessionService_types.py]
* http://www.performiq.com.au/kb/images/SessionService_server.py]

Revision as of 13:29, 18 August 2008

All..

I'm using stubs generated from the latest (as of  yesterday) ZSI trunk. I need to be able to pass in credentials (user, pass, app name) thru the SOAP headers, so I am passing in a dict as kwargs to my Login() function. Please see attached stubs. Here's how I am calling the stubs, and I get a typecode error:

######################################################################################################

In [5]: from SessionService_client import *

In [6]: request=LoginSoapIn()

In [7]: loc=SessionServiceLocator()

In [8]: port=loc.getSessionServiceSoap("https://webservices1-2.ihsenergy.com/WebServices/Session")

In [12]: e=[('Username','user'),('Password','pass'),('Application','app')]

In [14]: res=port.Login(request,e)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

C:\python24\scripts\<ipython console>

C:\python24\scripts\SessionService_client.py in Login(self, request, soapheaders, **kw)
     40         # no input wsaction
     41         # TODO: Check soapheaders
---> 42         self.binding.Send(None, None, request, soapaction="http://www.ihsenergy.com/Enerdeq/Schemas/Session/Logi

n", soapheaders=soapheaders, **kw)
     43         # no output wsaction
     44         response = self.binding.Receive(LoginSoapOut.typecode)

C:\Python24\lib\site-packages\ZSI\client.py in Send(self, url, opname, obj, nsdict, soapaction, wsaction, endPointRefere

nce, soapheaders, **kw)
    250
    251         for i in soapheaders:
--> 252            sw.serialize_header(i,typecode=requesttypecode)
    253
    254         #

C:\Python24\Lib\site-packages\zsi\writer.py in serialize_header(self, pyobj, typecode, **kw)
     76         typecode = getattr(pyobj, 'typecode', typecode)
     77         if typecode is None:
---> 78             raise RuntimeError(
     79                    'typecode is required to serialize pyobj in header')
     80

RuntimeError: typecode is required to serialize pyobj in header

################################################################################################################

So I try to set the typecode to Array:

In [20]: request.typecode='Array'

But then I get an attribute error:

################################################################################################################

In [24]: res=port.Login(request,e)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

C:\python24\scripts\<ipython console>

C:\python24\scripts\SessionService_client.py in Login(self, request, soapheaders, **kw)
     40         # no input wsaction
     41         # TODO: Check soapheaders
---> 42         self.binding.Send(None, None, request, soapaction="http://www.ihsenergy.com/Enerdeq/Schemas/Session/Logi

n", soapheaders=soapheaders, **kw)
     43         # no output wsaction
     44         response = self.binding.Receive(LoginSoapOut.typecode)

C:\Python24\lib\site-packages\ZSI\client.py in Send(self, url, opname, obj, nsdict, soapaction, wsaction, endPointRefere

nce, soapheaders, **kw)
    245                 tc = TC.Any(pname=opname, aslist=False)
    246
--> 247             sw.serialize(obj, tc)
    248         else:
    249             sw.serialize(obj, requesttypecode)

C:\Python24\Lib\site-packages\zsi\writer.py in serialize(self, pyobj, typecode, root, header_pyobjs, **kw)
    115             elt = typecode.serialize(self.dom, self, pyobj, **kw)
    116         else:
--> 117             elt = typecode.serialize(self.body, self, pyobj, **kw)
    118
    119         if root is not None:

C:\Python24\Lib\site-packages\ZSI\TC.py in serialize(self, elt, sw, pyobj, name, **kw)
    607     def serialize(self, elt, sw, pyobj, name=None, **kw):
    608         if hasattr(pyobj, 'typecode') and pyobj.typecode is not self:
--> 609             pyobj.typecode.serialize(elt, sw, pyobj, **kw)
    610             return
    611

AttributeError: 'str' object has no attribute 'serialize'

################################################################################################################

Can someone tell me if I am approaching this correctly? Am I sending the credentials for headers correctly into my Login() function as a list of tuples?

And am I setting the typecode properly, and is the typecode for the list of tuples indeed 'Array'?

Thanks

chad

<<SessionService_server.py>> <<SessionService_client.py>> <<SessionService_types.py>>


See: