SOAP - Examples

From PeformIQ Upgrade
Revision as of 13:13, 9 November 2007 by PeterHarding (talk | contribs) (New page: TableOfContents = Web Services Stuff = == demo.targetprocess.com == I am connected to two different WebServices that use the same name. {{{ http://demo.targetprocess.com/Services/I...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

TableOfContents

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


>>>


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 }}}