Difference between revisions of "ZSI Notes"
PeterHarding (talk | contribs) |
PeterHarding (talk | contribs) |
||
Line 6: | Line 6: | ||
Fragments extracted from Pywebsvcs-talk Digest, Vol 34, Issue 6 | Fragments extracted from Pywebsvcs-talk Digest, Vol 34, Issue 6 | ||
Also see http://lucasmanual.com/mywiki/SOAP | |||
Below only lists available functions.... | Below only lists available functions.... |
Revision as of 15:15, 24 March 2009
Some Notes from Pywebsvcs-talk@lists.sourceforge.net List
My scrapbook of notes and extracts from the Pywebsvcs mailing list...
Finding Methods
Fragments extracted from Pywebsvcs-talk Digest, Vol 34, Issue 6
Also see http://lucasmanual.com/mywiki/SOAP
Below only lists available functions....
.... s=ServiceProxy(url,tracefile=sys.stdout) .... from ZSI.schema import GED print s._methods.keys() for x in s._methods.keys(): for i in s._methods[x][0].callinfo.inparams: print 'Inparameters',i.name,i.type,GED(*i.type) for i in s._methods[x][0].callinfo.outparams: print 'outparameters',i.name,i.type,GED(*i.type)
Try This
Fragments extracted from Pywebsvcs-talk Digest, Vol 34, Issue 5
Try this: >>> from ZSI.ServiceProxy import ServiceProxy as sp >>> s = sp("yoururl.wsdl") >>> dir(s)
Ok. This does what? Connects me?
1. Now, there is a request function that I need to use. How can I find it? Where is it?
dir(s) ['__doc__', '__init__', '__module__', '_asdict', '_cachedir', '_call', '_force', '_kw', '_lazy', '_load', '_load_schema', '_methods', '_mod', '_name', '_nullpyclass', '_port', '_pyclass', '_service', '_url', '_wsdl']
2. The service I'm connecting to has a function that takes 3 arguments, so I assume somewhere I should be able to do:
processed_xml=somecallfunction(username='lucas',password='xyz',file='myxmlfile.xml')
How do I call that function? How do I list available "call functions"
? Anything else I need to do?
Actually the problem seems to be: It looks like WCF hides some of their stuff in the WSDL, but they tell you where it is with their import schemas: <wsdl:types> - <xsd:schema targetNamespace="http://tempuri.org/Imports"> <xsd:import schemaLocation="http://someurl.com/service.svc?xsd=xsd0" namespace="http://tempuri.org/" /> <xsd:import schemaLocation="http://someurl.com/service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" /> </xsd:schema> </wsdl:types> Is there a way I can get my ServiceProxy read that file? from ZSI.ServiceProxy import ServiceProxy as sp >>>>> s = sp("yoururl.wsdl") ????? It doesn't seem to follow the target schema?
Not sure who's fault was that....,I got the people to modify the wsdl and now I can see the "submit and rate" function. 1. How do I use it ..From soappy examples I can see I could do the following, but in zsi? from SOAPpy import WSDL >>> server = WSDL.Proxy('/path/to/your/GoogleSearch.wsdl') server.methods.keys() 2 [u'doGoogleSearch', u'doGetCachedPage', u'doSpellingSuggestion'] >>> callInfo = server.methods['doGoogleSearch'] >>> for arg in callInfo.inparams: 3 ... print arg.name.ljust(15), arg.type and results = server.doGoogleSearch(key, 'mark', 0, 10, False, "", ... False, "", "utf-8", "utf-8") 2. I tried with zsi: url='http:/someurl....com' from ZSI.ServiceProxy import ServiceProxy as sp s=sp(url) f=open(somefile.xml','r') file=f.readlines() f.close() s.SubmitAndRate('myusername','mypassword','1234',file) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/var/lib/python-support/python2.5/ZSI/ServiceProxy.py", line 324, in __call__ return self.parent()._call(self.__name__, self.soapheaders)(*args, **kwargs) File "/var/lib/python-support/python2.5/ZSI/ServiceProxy.py", line 204, in call_closure raise TypeError, 'Not supporting SOAPENC:Arrays or XSD:List' TypeError: Not supporting SOAPENC:Arrays or XSD:List
On the Usefulness of ZSI
Extracted from Pywebsvcs-talk Digest, Vol 30, Issue 3
Works fine for me, as far as client WSDL/SOAP is concerned. But the bigger problem is XSD files that turn quickly turn into monstrosities. I use Code Synthesis' xsd-tree for parsing xsd specifications and serializing the data, then pack them in with ZSI to send them off to the server. I've tried Java (jaxb,jaxm), mono -C# (with Microsofts XSD), gSoap and Perl soap::lite. I found the java variations seriously over engineered (a class file per element), (the mono XSD was seriously deficient. Its /c to generate c++ didn't work on linux, and C# under mono is really just a specification), and Perl soap::lite out of date (didn't work with the .net services I had to deal with) Had I had some more time, I might have made gSoap work, but ZSI tackled the WSDL I had to work with right out of the tarbox. And when something was unclear or didn't work, I could step through with the python debugger to track it down. I work on linux. If I had been developing on M$, I would have used their stuff, but I still think I would stick with Code Synthesis and C++ for parsing xsd. It's a fantastic program with unbelievably good support for an open source product, and works with Visual Studio,too. ZSI's support is ok, too. The turnaround on questions is pretty slow. But if you don't mind stepping through the code, you can usually fix the problem yourself. And there seem to be plenty of people using it. Roger Evans
Having spent too much time recently looking at python/SOAP stuff I am pretty sure ZSI is the only one out there that will go any way towards handling the WSDL part for you. I am more than willing for someone to correct me on this if I missed anything. -- Peter Ellis <peter.ellis@finalhaven.org>
alphabetical order of 'self.attribute_typecode_dict'
This should be irrelevant, although order is important for canonicalization for an entirely different matter.
I think you could retain your ordering by replacing the underlying dict with your own dict subclass that maintains a list too.
Topic._attrs = OrderDict()
Something like Collection, although obviously this is a bit old.
from ZSI.wstools.Utility import Collection class Collection(UserDict): """Helper class for maintaining ordered named collections.""" default = lambda self,k: k.name def __init__(self, parent, key=None): UserDict.__init__(self) self.parent = weakref.ref(parent) self.list = [] self._func = key or self.default def __getitem__(self, key): if type(key) is type(1): return self.list[key] return self.data[key] def __setitem__(self, key, item): item.parent = weakref.ref(self) self.list.append(item) self.data[key] = item def keys(self): return map(lambda i: self._func(i), self.list) def items(self): return map(lambda i: (self._func(i), i), self.list) def values(self): return self.list
Newbie Stuff
Upgrade to ZSI-2.1a and this package is no longer required. -josh On May 14, 2008, at 4:02 PM, freeav8r wrote: > Hi all: > > I’m new to ZSI and apache and I’m having > difficulty getting my first ZSI web service up and > running. > > I installed apache with no problems and also installed > mod_python. I ran the mod_python “hello world” > test by changing the httpd.conf file with the > following entry: > > <Directory "C:/Program Files/Apache Software > Foundation/Apache2.2/htdocs/test"> > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On > </Directory> > > The “Hello world” worked fine. > > I tried the mod_python example (2.1.3) found here: > http://pywebsvcs.sourceforge.net/zsi.html > > Because of the apache config entry above, I created > the following to files with the below names: > > ========== mptest.py ========= > from ZSI import dispatch > from mod_python import apache > > import MyHandler > mod = __import__('encodings.utf_8', globals(), > locals(), '*') > mod = __import__('encodings.utf_16_be', globals(), > locals(), '*') > > def handler(req): > dispatch.AsHandler(modules=(MyHandler,), > request=req) > return apache.OK > ========== end mptest.py ======= > > =========MyHandler.py ======== > def hello(): > return "Hello, world" > > def echo(*args): > return args > > def average(*args): > sum = 0 > for i in args: sum += i > return sum / len(args) > ========= end MyHandler.py ======== > > When I request the mptest.py file I get the following > error: > > > File "C:\Program > Files\Python25\Lib\site-packages\ZSI\parse.py", line > 54, in __init__ > from xml.dom.ext.reader import PyExpat > > ImportError: No module named ext.reader > > I'm running python 2.5 and the lastest stable versions > of apache, mod_python, and ZSI. > > > Any ideas? > > -freeav8r
http persistent connection
I think you can do this by using your own transport. Here is the relevant code from client.py: self.h = transport(netloc, None, **self.transdict) self.h.connect() self.SendSOAPData(soapdata, url, soapaction, **kw) So basically you'd need something like a Singleton that delegates to actual transports, so you can maintain these instances between soap calls and reuse the same transport when appropriate. But I'm not sure about the rest, you'll need a transport that implements HTTP persistent connections. Maybe twisted is a better bet than the python httplib. -josh On May 17, 2008, at 2:52 PM, Kleber Carriello de Oliveira wrote: > Sirs, > > I'm trying to use ZSI with http persistent connection, does anyone > know if it's possible? If yes can you send me one example? > > My problem is that I need to call one API about 500 times per > second... I believe that using persistent connection I can reach > this number instead of open and close one tcp connection each time I > do a call. > > Thanks in advance, > > Kleber Carriello > > > Abra sua conta no Yahoo! Mail, o único sem limite de espaço > para armazenamento! > http://br.mail.yahoo.com/
ServiceProxy
> server = ServiceProxy(w, pyclass=True, tracefile=sys.stdout) ZSI 2.0.0 as a whole supports complex type, but there's a serious bug in ServiceProxy in 2.0.0 which prevents using it with asdict=False (ServiceProxy in 2.0.0 doesn't have the pyclass keyword) [1]. I suggest upgrading to 2.1a1 where the broken part of ServiceProxy has been rewritten and now works. [1] Specifically ServiceProxy._call always passes args or kwargs through to binding.Send regardless of what asdict is set to, so that with complex types calls to proxy methods complain that binding.Send is getting tuples (i.e. args) or dicts (i.e. kwargs) instead of the expected complex types.
ZSI Thread Safe?
I don't think so but threads in python are restricted by the GIL so all state is shared between threads. So if you're changing an objects state all threads will "instantly" see it. This is up to you to manage. -josh On May 14, 2008, at 12:56 AM, Esteban wrote: > After some testing, I confirmed that I cannot share the same > ServicePort on different clients as it is not thread safe (I expected > this result actually...) > > Using a different one for each client seems to work. However, I am > concerned about race conditions that are difficult to detect. Does > somebody know whether the servicePorts share any resources that could > lead to the wrong result if accessing through several threads? > > Thanks, > -- Esteban. > > On May 13, 10:01 am, Esteban <robe...@gmail.com> wrote: >> Hi there, >> >> I am writting a client for a Web Service using ZSI 2.0. >> I have to poll different operations on the same service, using >> different time intervals. >> I'd like to use a separate thread for each operation, so that one of >> them can execute while others are either sleeping or blocked waiting >> for the service's response. >> >> Is the service binding returned by >> ServiceLocator().getServicePort(url, **kw) thread safe (so that it >> can >> be shared by all client threads)? In case it is not, would it be any >> problem if I create a different service locator as above on each >> thread? I am not sure if they would share any common stuff in >> downstream... >> >> I read a similar post (http://groups.google.com/group/pywebsvcs/ >> browse_thread/thread/cf77b338ccb1e526/26a4e4dcfec57564? >> lnk=gst&q=thread#26a4e4dcfec57564) >> but I did not really get it clear and I think it was more focused on >> the service side (as it talked about Apache for example). >> >> Any other suggestion to approach this problem are appreciated ;) >> >> Thanks for your help, >> -- Esteban >>
Simple Client Example
Joshua Boverhof escribió: You can use WSDL too (wsdl2py), but here is a simple client example -josh $ python Python 2.5.1 (r251:54863, May 23 2007, 10:06:54) [GCC 4.0.0 20041026 (Apple Computer, Inc. build 4061)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from ZSI.client import * >>> dir() ['AUTH', 'Address', 'AnyElement', 'AnyType', 'Binding', 'Cookie', 'EvaluateException', 'FaultException', 'FaultFromFaultMessage', 'NamedParamBinding', 'ParsedSoap', 'SoapWriter', 'String', 'Struct', 'TC', 'TypeCode', 'UNICODE_ENCODING', 'WSActionException', 'ZSI_SCHEMA_URI', '__builtins__', '__doc__', '__name__', 'base64', 'httplib', 'time', 'types', 'urlparse'] >>> import sys >>> cli = NamedParamBinding("http://www.google.com", tracefile=sys.stdout) >>> cli.Hello() _________________________________ Tue May 13 23:09:21 2008 REQUEST: <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/ " xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP- ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><Hello></Hello></SOAP- ENV:Body></SOAP-ENV:Envelope> _________________________________ Tue May 13 23:09:22 2008 RESPONSE: 501 Not Implemented ------- Date: Wed, 14 May 2008 06:09:22 GMT Content-Type: text/html; charset=UTF-8 Server: gws Content-Length: 1343 ... ... >>> cli.Hello(first="Jenn", lastname="Duerr", number=1) _________________________________ Tue May 13 23:11:03 2008 REQUEST: <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/ " xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP- ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP- ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><Hello><lastname id="o1454e20" xsi:type="xsd:string">Duerr</lastname><number id="o803588" xsi:type="xsd:int">1</number><first id="o1454de0" xsi:type="xsd:string">Jenn</first></Hello></SOAP-ENV:Body></SOAP- ENV:Envelope> _________________________________ Tue May 13 23:11:03 2008 RESPONSE: 501 Not Implemented ------- Date: Wed, 14 May 2008 06:11:03 GMT Content-Type: text/html; charset=UTF-8 Server: gws Content-Length: 1343 Connection: Close
Wolfram Services
I have dowloaded/installed the following with no errors: Python 2.6 ZSI-2.0 MingGW-5.1.4 PyXML-0.8.4 I am running on a PC. When running the following python code (from ZSI users guide) I get the following errors. Thanks for your HELP import sys import timing from ZSI.generate.commands import wsdl2py #Connect and build the python files based on wsdl url #wsdlurl = 'http://webservices.wolfram.com/services/SearchServices/WolframSearch2.wsdl' #args = ['-bu', wsdlurl] #wsdl2py(args) # import the generated class stubs from WolframSearchService_services import * # get a port proxy instance loc = WolframSearchServiceLocator() port = loc.getWolframSearchmyPortType() # create a new request req = WolframSearchRequest() req.Options = req.new_Options() req.Options.Query = 'newton' # call the remote method resp = port.WolframSearch(req) <==== ERROR OCCURS HERE # print results print 'Search Time:', resp.Result.SearchTime print 'Total Matches:', resp.Result.TotalMatches for hit in resp.Result.Matches.Item: print hit.Title --------------------------------------------------------------------------- HERE IS THE ERRORS.... Web Service Access!! Traceback (most recent call last): File "C:\eclipse\workspace\TestCtsWebService\src\root\examples\wsTestWolframeSearch.py", line 30, in <module> resp = port.WolframSearch(req) File "C:\eclipse\workspace\TestCtsWebService\src\root\examples\WolframSearchService_services.py", line 105, in WolframSearch response = self.binding.Receive(WolframSearchResponse.typecode) File "C:\Python26\lib\site-packages\ZSI\client.py", line 498, in Receive self.ReceiveSOAP(**kw) File "C:\Python26\lib\site-packages\ZSI\client.py", line 398, in ReceiveSOAP encodingStyle=kw.get('encodingStyle')) File "C:\Python26\Lib\site-packages\ZSI\parse.py", line 54, in __init__ from xml.dom.ext.reader import PyExpat ImportError: No module named ext.reader
> from xml.dom.ext.reader import PyExpat > > ImportError: No module named ext.reader The Expat parser is included in Python 2.6 by default and is available via xml.parsers.expat. ZSI will probably have to be updated to reflect this -- perhaps it already has been? I would try ZSI 2.1a1 and then ask again if the problem persists there
wsdl2py
Hi, I'm having an issue with a type I have defined for my response in my wsdl. One of the elements in my response is an xsd:list, which is just a list of strings seperated by space. Here is the definition of the element: <xsd:element name="linkedapplications" type="tnsb:linkedApplicationsList"/> <xsd:simpleType name="linkedApplicationsList"> <xsd:annotation> <xsd:documentation></xsd:documentation> </xsd:annotation> <xsd:list> <xsd:simpleType> <xsd:restriction base="xsd:string"></xsd:restriction> </xsd:simpleType> </xsd:list> </xsd:simpleType> I then run: wsdl2py -b file.wsdl And it auto generates my stubs. Then testing the service it works fine if the <linkedapplications> element is empty. But if it contains any values, such as <linkedapplications>value1</linkedapplications> or <linkedapplications>value1 value2</linkedapplications> It throws the following error: Traceback (most recent call last): resp = port.registerUserOrAddToGroup(req) File "generatedServices_client.py", line 41, in registerUserOrAddToGroup response = self.binding.Receive(registerUserOrAddToGroupResponse.typecode) File "build/bdist.cygwin-1.5.25-i686/egg/ZSI/client.py", line 536, in Receive return _Binding.Receive(self, replytype, **kw) File "build/bdist.cygwin-1.5.25-i686/egg/ZSI/client.py", line 461, in Receive reply = self.ps.Parse(tc) File "build/bdist.cygwin-1.5.25-i686/egg/ZSI/parse.py", line 326, in Parse return how.parse(self.body_root, self) File "build/bdist.cygwin-1.5.25-i686/egg/ZSI/TCcompound.py", line 196, in parse value = what.parse(c_elt, ps) File "build/bdist.cygwin-1.5.25-i686/egg/ZSI/TC.py", line 1672, in parse return self.text_to_data(v, elt, ps) File "build/bdist.cygwin-1.5.25-i686/egg/ZSI/TC.py", line 1643, in text_to_data v.append(self.itemTypeCode.text_to_data(item, elt, ps)) AttributeError: 'NoneType' object has no attribute 'text_to_data' Is the definition of xsd:list allowed to by empty or do I have to specify enumerations? I have seen examples that allow non enumerated xsd:list types. Any help would be appreciated. Cheers, Jaie