Web Service Stuff

From PeformIQ Upgrade
Jump to navigation Jump to search

Web Services Stuff

demo.targetprocess.com

I am connected to two different WebServices that use the same name.

http://demo.targetprocess.com/Services/IterationService.asmx
http://demo.targetprocess.com/Services/UserStoryService.asmx

They have the same name and method:

http://targetprocess.com/RetrieveAllForProject

Stubs for these services were created with wsdl2py -b url

One returns IterationDTO and one UserStoryDTO.

When i create a class that uses both webservices i get into trouble. The one i import first creates a object for the name/method. When the other one is imported it doesn't create an object or it simply uses the first one created.

  AttributeError: 'ArrayOfUserStoryDTO_Holder' object has no attribute 'IterationDTO'

It should be ArrayofIterationDTO_Holder, but since i imported UserStory service first its ArrayOfUserStoryDTO_Holder.


WSDL-1.1 are full of errors

The schemas for WSDL-1.1 are full of errors, so they aren't useful for validation. I tried cleaning them up but it's just too much to do right now.

Try this:

	%python -c "from ZSI.wstools.WSDLTools import WSDLReader as wsr; print  wsr().loadFromFile('INFOSearch.wsdl')"

should give you a more informative error.

On Nov 7, 2007, at 10:29 AM, Barrett wrote:

> Thanks, Josh.  I tried the xmllint command you suggested, but all  it's doing
> is printing back the content of the wsdl.  No message as to whether or not
> it's valid.  Adding the --valid option to the call gives me a  message that
> validation failed because there's no DTD.  I haven't been able to  find a WSDL
> DTD to validate it against.  Do you know of one?
>
> As far as the version, I pulled the 2.0 release from
> pywebscvs.sourceforge.net.  Is there a newer version?
>
> Thanks,
> Barrett
>
> PS - Apologies for the lack of a from header in my original post.   
> My webmail
> client is apparently fritzy.
>
> On Wednesday 07 November 2007 01:05:32 pm Joshua Boverhof wrote:
>> I don't know, the tooling failed to load the WSDL file, but it should
>> print out the traceback to stderr and I don't see that.
>>
>> try this:
>>
>> 	% xmllint INFOSearch.wsdl
>>
>>
>> which will tell you if it's legal XML
>>
>> Otherwise maybe you're using an older ZSI which doesn't print out the
>> traceback for the wsdl2py command line tool...
>>
>> -josh
>>
>> On Nov 6, 2007, at 6:48 AM, <> <> wrote:
>>
>>> I have a web service implemented using PHP's NuSOAP library for which I'm
>>> trying to create a Python client.  I'm getting errors, though, trying to use
>>> wsdl2py to create the stub code for me.  When I try to run it, I get the
>>> output below.
>>>
>>> I'm assuming it's a problem with either my WSDL or the imported XSD files,
>>> but don't know where to look for the source of the problem.  Can anyone
>>> offer a suggestion of where I should be looking and/or for what?
>>>
>>> $ wsdl2py -dbf INFOSearch.wsdl
>>> Error loading INFOSearch.wsdl:
>>> 'NoneType' object is not callable


Echo Server

Your client is a problem.  Twisted is a little different.  Give this
script a shot, also since you're using the "-b" option take advantage
of the properties as I do below.  I ran this w/o problems.

-josh


from twisted.internet import reactor
import EchoServer_client

def main(url):
     loc = EchoServer_client.EchoServerLocator()
     port = loc.getEchoServer(url)
     msg = EchoServer_client.EchoRequest()
     msg.EchoIn = "bla bla bla bla"
     rsp = port.Echo(msg)
     print "rsp.EchoResult=",rsp.EchoResult
     reactor.callLater(.01, reactor.stop)
     return

reactor.callWhenRunning(main, 'http://localhost:7000/test')
reactor.run()



On Aug 14, 2007, at 6:31 AM, Arye wrote:

> Hello,
>
> With  "twisted=True" in "config.txt"
> the "test_Echo.py" runs fine on Unix.
> Thanks for adding this. However
> could you please explain what I am missing
> in order to run this "Echo" server without the unittest.
>
> This is what I did:
>
> 1) Create a directory called "Echo" and copy
> "\zsi\samples\Echo\Echo.wsdl" in it
>
> 2) run wsdl2py -b -w Echo.wsdl
>
> 3) copy the actual server from "zsi\test\wsdl2py\servers
> \EchoServer.py"
> and run it with:
>> python EchoServer.py 7000
>
> 4) run the client below:
> ***************begin**********
> import EchoServer_client
> loc = EchoServer_client.EchoServerLocator()
> port = loc.getEchoServer()
>
> msg = EchoServer_client.EchoRequest()
> msg._EchoIn = "bla bla bla bla"
> rsp = port.Echo(msg)
> print "rsp._EchoResult=",rsp._EchoResult
> ****************end************
>
> This is where I fail to connect to the server.
> The "port.Echo(msg)" call times out.
> (I tried to get the port with :
> port = loc.getEchoServer(url='http://localhost:7000/test')
> with no more success)
>
>
> Any info you might have on what I missed would
> once again be greatly appreciated.
>
> Sincerely,
> Arye.
>
> On 8/8/07, Joshua Boverhof <jrboverhof@lbl.gov> wrote:
>> just getting back from vacation,  I changed the code to catch this
>> exception.  I also added some code to generate server stubs for
>> ZSI.twisted.WSresource, WSResource.
>>
>>
>> Revision: 1412
>>            http://pywebsvcs.svn.sourceforge.net/pywebsvcs/?
>> rev=1412&view=rev
>> Author:   boverhof
>> Date:     2007-08-07 15:56:37 -0700 (Tue, 07 Aug 2007)
>>
>>
>>
>> -josh
>>
>>
>> On Jul 27, 2007, at 12:25 AM, Arye wrote:
>>
>>> On 7/27/07, Joshua Boverhof <jrboverhof@lbl.gov> wrote:
>>>> You should be able to go to "zsi/test/wsdl2py", edit the
>>>> "config.txt"
>>>> file so that
>>>>
>>>>         twisted=True
>>>>
>>>> then run:
>>>>
>>>>         python test_Echo.py
>>>>
>>>> You'll see the client stubs use a twisted client, however, I don't
>>>> think the server-side is generated to use twisted so I'll need
>>>> to add
>>>> this in.
>>>
>>> Hello, until you add this to the tests, could you please confirm
>>> that
>>> the server stubs can be generated to use Twisted and that there
>>> are no
>>> known problems using them ?
>>>> From what I could see by looking at the generated files, the
>>>> server and
>>> client stubs are generated to use Twisted, but some some reason
>>> (probably some error I made ) the server does not seem to answer.
>>>
>>> I tried the test_Echo.py with Twisted and here is the output:
>>>
>>> ********Win32:**************
>>>   File "C:\AH\DEV\zsi\test\wsdl2py\ServiceTest.py", line 361, in
>>> CleanUp
>>>     os.kill(cls._process.pid, signal.SIGKILL)
>>> exceptions.AttributeError: 'module' object has no attribute 'kill'
>>> ********End Win32:**************
>>>
>>>
>>> ********Red Hat**************
>>> python test_Echo.py
>>> localhost.localdomain - - [27/Jul/2007 09:12:13] "POST /test HTTP/
>>> 1.0" 200 -
>>> .
>>> |------------------------------------------------------------
>>> |  TestCase: test_dispatch_Echo
>>> |--------------------
>>> |  run time:   176.643133163 ms
>>> |  return  :   None
>>> |------------------------------------------------------------
>>> E
>>> ====================================================================
>>> ==
>>> ERROR: test_local_Echo (__main__.EchoTestCase)
>>> --------------------------------------------------------------------
>>> --
>>> Traceback (most recent call last):
>>>   File "/home/ah/pywebsvcs/test/wsdl2py/ServiceTest.py", line 185,
>>> in run
>>>     self.setUp()
>>>   File "/home/ah/pywebsvcs/test/wsdl2py/ServiceTest.py", line 307,
>>> in setUp
>>>     self._generate()
>>>   File "/home/ah/pywebsvcs/test/wsdl2py/ServiceTest.py", line 277,
>>> in _generate
>>>     commands.wsdl2py([url] + self.wsdl2py_args)
>>>   File "build/bdist.linux-i686/egg/ZSI/generate/commands.py", line
>>> 126, in wsdl2py
>>>   File "/usr/local/lib/python2.4/optparse.py", line 1277, in
>>> parse_args
>>>     stop = self._process_args(largs, rargs, values)
>>>   File "/usr/local/lib/python2.4/optparse.py", line 1317, in
>>> _process_args
>>>     self._process_long_opt(rargs, values)
>>>   File "/usr/local/lib/python2.4/optparse.py", line 1392, in
>>> _process_long_opt
>>>     option.process(opt, value, values, self)
>>>   File "/usr/local/lib/python2.4/optparse.py", line 709, in process
>>>     return self.take_action(
>>>   File "/usr/local/lib/python2.4/optparse.py", line 728, in
>>> take_action
>>>     self.callback(self, opt, value, parser, *args, **kwargs)
>>>   File "build/bdist.linux-i686/egg/ZSI/generate/commands.py",
>>> line 42,
>>> in SetUpTwistedClient
>>>     def getoutput(cmd):
>>> ValueError: list.remove(x): x not in list
>>>
>>> --------------------------------------------------------------------
>>> --
>>> Ran 2 tests in 1.268s
>>>
>>> FAILED (errors=1)
>>> ********end Red Hat**************
>>>
>>>> -josh
>>>>
>>>>
>>>>
>>>> On Jul 26, 2007, at 3:08 AM, Arye wrote:
>>>>
>>>>> Hello all,
>>>>>
>>>>> Without the --twisted option, the server and client run fine.
>>>>> When generating the stubs with this option, I get a
>>>>> TimeoutError when trying to run the client.
>>>>>
>>>>> I am using ZSI from svn, and tried this with Python 2.4 and 2.5
>>>>> and Twisted 2.4 and 2.5.
>>>>>
>>>>> Any working example for instance of the echo service
>>>>> generated with the --twisted option would be greatly appreciated.
>>>>>
>>>>> All the best,
>>>>> Arye.
>>>>>
>>>>> ------------------------------------------------------------------
>>>>> --
>>>>> --
>>>>> ---
>>>>> This SF.net email is sponsored by: Splunk Inc.
>>>>> Still grepping through log files to find problems?  Stop.
>>>>> Now Search log events and configuration files using AJAX and a
>>>>> browser.
>>>>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>>>>> _______________________________________________
>>>>> Pywebsvcs-talk mailing list
>>>>> Pywebsvcs-talk@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
>>>>> Also archived at http://groups.google.com/group/pywebsvcs
>>>>
>>
>
> ----------------------------------------------------------------------
> ---
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a
> browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Pywebsvcs-talk mailing list
> Pywebsvcs-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
> Also archived at http://groups.google.com/group/pywebsvcs


Raw XML

posting solution to list:




I think you need to use a DOM node.


Something like this from "test/wsdl2py/test_NVOAdmin.py"


        input = open('wsdl/nvo-admin.wsdl').read()
        reader = PyExpat.Reader()
        dom = reader.fromString(input)


        dnode =  _child_elements(dom)[0]
        tnode =  _child_elements(dnode)[0]
        snode =  _child_elements(tnode)[0]


        msg.DSQueryRegistryResult.Schema = snode




Here is what happens if you specify a str:




   1276     def cb(self, elt, sw, pyobj, unsuppressedPrefixes=[]):
   1277         """pyobj -- xml.dom.Node.ELEMENT_NODE
   1278         """
   1279         #if sw.Known(pyobj):
   1280         #    return
   1281
   1282         if type(pyobj) in _stringtypes:
   1283             elt.createAppendTextNode(pyobj)
   1284             return
   1285






So if you dump a DOM node into this function (XML.cb), it will behave differently  (no escapes).
-josh










On Aug 9, 2007, at 11:41 AM, Eric Anderson wrote:


On the following page: http://article.gmane.org/gmane.comp.python.pywebsvcs.general/2217

I found a question (dated 2007-05-31) about sending raw xml with ZSI, and the answer (dated 2007-06-01) was that you needed to grab the latest ZSI source to make TC.XML work.  I have done that, but ZSI is still translating the > in my raw xml to >

Is there a way to send the raw xml through ZSI without that translation occurring?

Thank you very much for your help.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/_______________________________________________
Pywebsvcs-talk mailing list
Pywebsvcs-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
Also archived at http://groups.google.com/group/pywebsvcs
}}}

== ZSI.TC ==

{{{
the instances you're comparing are equivalent, both are legal XML, and both follow the schema.


Now if .NET doesn't digest ZSI output, I'll hold my nose and direct you to a solution or two.


1) You may try declaring all the namespaces in the envelope using the "nsdict" parameter.


2) You could replace the ElementProxy with one I posted on the list a while back that did this same thing.




Check out this page:


http://dev.globus.org/wiki/Python/ZSI/TRUNK/FAQ








-josh




On Aug 13, 2007, at 10:02 AM, Julius Lucks wrote:


Hi Eric,

The documentation for ZSI.TC is really confusing IMHO.  From what I can tell, TC does not determine how the namespaces are printed out. I have not dealt with the requests myself (only the server responses),  but to change how the response was printed, I eventually had to dig into the code, particularly within the _Dispatch method found in  dispatch.py .  For the request, you might have to dig in client.py in the _Binding.Send method.  Look for variables called tc.  Sorry I can't be of more help, but please let me know if you find out how to do this.

Cheers,

Julius


On 8/13/07, Eric Anderson <eric@yapta.com> wrote:
Julius --

I saw your response yesterday about ZSI.TC.Struct to the pywebsvcs newsgroup.  You said:



An example would be

My_Class.typecode = ZSI.TC.Struct(My_Class,
                                           [ ZSI.TC.String('my_var'),
                                             ZSI.TC.Array((' http://www.w3.org/2001/XMLSchema ',
                                                                 'string[]'), ZSI.TC.String(),pname='my_list')
                                           ],
                                           pname=('urn:My_URN','My_CLass'))


Look at ZSI.TC to see how to setup the typecode for your MyClass.  Note that you need to use that last pname bit in the typecode definition to ensure that the SOAP-Env:Body element is formed properly.


---

That generates a request of the form:

<SOAP-ENV:Body xmlns:ns1="urn:webservices.galileo.com ">
  <ns1:My_CLass>
    <my_var xsi:type="xsd:string">
etc.


---

How can I generate a request of the form:


<SOAP-ENV:Body>
  <My_CLass xmlns="http//myns.com">
    <my_var xsi:type="xsd:string">


using TC.Struct?  Note, I want the xmlns to appear in the My_CLass line, not the Body line.

Newby Question

Looks like a parameter is missing, not sure how/why this happened.

-josh



svn diff dispatch.py
Index: dispatch.py
===================================================================
--- dispatch.py (revision 1409)
+++ dispatch.py (working copy)
@@ -141,7 +141,7 @@
              # reponse typecode
              #tc = getattr(result, 'typecode', TC.Any(pname=what
+'Response'))
-            tc = TC.Any(pname=what+'Response')
+            tc = TC.Any(pname=what+'Response', aslist=isarray)
          sw = SoapWriter(nsdict=nsdict)
          sw.serialize(result, tc)





On Aug 6, 2007, at 11:31 PM, Mr Torsten Will wrote:

> Hi,
>
> when I followed the tutorial I set up a simple RPC server and a
> client. I do not get the types of objects back that I expect, nor
> what is mentioned in the tutorial.
>
> My simple http-server:
>   #!/usr/bin/env python
>   from ZSI import dispatch
>   def echo(*args):
>       return args
>   dispatch.AsServer(rpc=True, port=8042)
>
> My client:
>   #!/usr/bin/env python
>   from ZSI import *
>   import sys
>   from ZSI.client import Binding
>   b = Binding(url='http://localhost:8042', tracefile=sys.stdout)
>   print "ECHO ", b.echo(*[u"One", 2, "Three"])
>
> The b.echo() call returns a very strange dictionary:
>   {'Eo2b2036c738a0': u'Three', 'Eo6577e0': 2, 'Eo2b2036c73fc0':
> u'One'}
>
>
> The reason might be, that the SOAP-Request recieved is not as it is
> mentioned in the tutorial, where the answer consists of
>   <element id="o2b2036c73fc0" ...>Thing</element>
> but of that one:
>   <Eo2b2036c73fc0 id="o2b2036c73fc0" xsi:type="xsd:string">One</
> Eo2b2036c73fc0>
>
>
> Where does the typecode/xml-element mapping to the break?
>
>
> Thanks in advance.
>
> tschau, towi.
>
>
>
> The complete trace is:
>
> 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>
>   <echo SOAP-ENC:arrayType="xsd:anyType[3]" xsi:type="SOAP-ENC:Array">
>     <element id="o2b539a77ef90" xsi:type="xsd:string">One</element>
>     <element id="o6577e0" xsi:type="xsd:int">2</element>
>     <element id="o2b539a77efc0" xsi:type="xsd:string">Three</element>
>   </echo>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>
>
>
> RESPONSE
>
> Server: ZSI/1.1 BaseHTTP/0.3 Python/2.5.1
> Date: Tue, 07 Aug 2007 06:18:39 GMT
> Content-type: text/xml; charset="utf-8"
> Content-Length: 608
>
>
>   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:Header></SOAP-ENV:Header>
> <SOAP-ENV:Body>
>   <echoResponse>
>     <Eo2b2036c73fc0 id="o2b2036c73fc0" xsi:type="xsd:string">One</
> Eo2b2036c73fc0>
>     <Eo6577e0 id="o6577e0" xsi:type="xsd:int">2</Eo6577e0>
>     <Eo2b2036c738a0 id="o2b2036c738a0" xsi:type="xsd:string">Three</
> Eo2b2036c738a0>
>   </echoResponse>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>
>
>
>
>
>
>
>
>
>
>       ___________________________________________________________
> Yahoo! Mail is the world's favourite email. Don't settle for less,
> sign up for
> your free account today http://uk.rd.yahoo.com/evt=44106/*http://
> uk.docs.yahoo.com/mail/winter07.html
>
> ----------------------------------------------------------------------
> ---
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a
> browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Pywebsvcs-talk mailing list
> Pywebsvcs-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
> Also archived at http://groups.google.com/group/pywebsvcs