SOAP problems

Rune Hansen rune.hansen at viventus.no
Mon Mar 10 16:03:30 EST 2003


Ah, well - yes. I'm absolutely no expert on SOAP and I'm inclined to 
agree with Johan Fredrik Øhman...
Anyways: The simplest of clients can be constructed like this:
(be shure to install ZSI 1.2-7)

---
from ZSI.client import Bindings
import sys

c = Binding(url='/',
             ns='',
             host='localhost',
             port=8080,tracefile=sys.stdout)

res = c.echo(1,2,3,4)
print res[0]

 >>[1,2,3,4]
 >>Output from trace
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:ZSI="http://www.zolera.com/schemas/ZSI/"
   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >
<SOAP-ENV:Body>
<echo>
<E810dc08 xsi:type="xsd:integer">1</E810dc08>
<E810dbf0 xsi:type="xsd:integer">2</E810dbf0>
<E810dbb4 xsi:type="xsd:integer">3</E810dbb4>
<E810dba8 xsi:type="xsd:integer">4</E810dba8>
</echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
.
.
.
---

This may be sufficient to communicate with the soapserver, "echo" beeing 
the SOAP service.

To send named parameters use:
---
from ZSI import *
from ZSI.client import NamedParamBinding
import sys

class Generic:
     def __init__(self,name):
         self.name = name

class tcMyParams(TC.Struct):
     def __init__(self, pname=None,**kw):
         print kw
	TC.Struct.__init__(self, Generic, [
	    TC.Iint('id',unique=1),
	    TC.String('username),
	    TC.String('password'),
             ], pname, inorder=0, **kw);

class myParams:
     typecode = tcMyParams('echo', typed=0)
     def __init__(self,id,username,password):
         self.id=id
         self.username=username
         self.password=password

def SOAPClient(id,username,password):
	soap_client = NamedParamBinding(url='',
         	                        			        ns='',
                 	                        			host='localhost',
                         	                			port=8080,
                                 	        			tracefile=sys.stdout)

         res = 
soap_client.RPC('/','echo',myParams(id,username,password),TC.Any(aslist=1))
	return res[0]

res = SOAPClient(100,'john','doe')

 >>Output from trace
<SOAP-ENV:Envelope
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:ZSI="http://www.zolera.com/schemas/ZSI/"
   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >
<SOAP-ENV:Body>
<echo>
<id>200</id>
<username id="816d0d8">john</username>
<password id="816faf8">doe</password>
</echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
---
This works for me..and since it works I haven't given it much thought. 
I've adapted the "named parameters" code from a Google/SOAP piece I 
found - it may or may not be the correct way to do it :-)

You'll find how to set up a simple SOAP server in one of the links i 
mentioned in my previous post.

Hope this will get you somewhere.

regards

/rune

Svenne Krap wrote:
> Ok. I'm gonna try it. Do you know some simple and accessible servers
> to try (most of the tuts' samples don't work). 
> 
> Small sample will be very appriciated.
> 
> Btw. I must call a function with a date argument (yyyy-mm-dd) and then
> I recieve an recordset as XML. 
> 
> So something like that would be very appriciated :)
> 
> Svenne
> 
> On Mon, 10 Mar 2003 16:32:57 +0100, Rune Hansen
> <rune.hansen at viventus.no> wrote:
> 
> 
>>Hi Svenne, your best option is to use ZSI 1.2 
>>(http://pywebsvcs.sourceforge.net/)
>>It's IMHO a far better SOAP library than Soapy.
>>
>>You should also take a look at:
>>http://www-106.ibm.com/developerworks/webservices/library/ws-pyth5/
>>http://www-106.ibm.com/developerworks/webservices/library/ws-pyth6/ and
>>http://www-106.ibm.com/developerworks/webservices/library/ws-pyth8.html
>>
>>regards
>>/rune
>>
>>Svenne Krap wrote:
>>
>>>How is this changed (ie. which files). 
>>>
>>>I have soap.py, soap.pyc and soap.pyo ? 
>>>Isn't there something like libs should be compiled (I am on Windows) ?
>>>
>>>Futher help appriciated :)
>>>
>>>Svenne
>>>
>>>On 6 Mar 2003 09:59:55 -0800, paul at boddie.net (Paul Boddie) wrote:
>>>
>>>
>>>
>>>>Svenne Krap <usenet2002 at krap.dk> wrote in message news:<8jbe6v8r3o6k2sme0e4uja2r4n9fac56pj at 4ax.com>...
>>>>
>>>>
>>>>>I have installed PyXML and Soapy ( http://soapy.sf.net ) . 
>>>>
>>>>[...]
>>>>
>>>>
>>>>
>>>>> File "C:\PROGRA~1\py222\soap.py", line 248, in load_namespaces
>>>>>   self.targetns = node.getAttributeNS('','targetNamespace')
>>>>
>>>>[...]
>>>>
>>>>
>>>>
>>>>>NamespaceErr: Use None instead of '' for empty namespace
>>>>>
>>>>>
>>>>>What does I do wrong ? Is there any way to fix it ? 
>>>>
>>>>I can imagine that Soapy was written to use the old convention of an
>>>>empty string meaning "empty namespace", but in more recent releases of
>>>>PyXML the convention is to use None for that purpose. As you can see
>>>
>>>>from the error and from the line in the traceback that I've quoted,
>>>
>>>
>>>>usage of '' with getAttributeNS (and probably other ...NS methods) is
>>>>the cause.
>>>>
>>>>To fix it, I would suggest doing a search for calls of methods whose
>>>>names end with NS and where the first argument is the empty string (''
>>>>and possibly ""). After testing, you might want to submit patches to
>>>>the Soapy project on SourceForge, or the Python Web Services project
>>>>if that's more appropriate.
>>>>
>>>>Good luck!
>>>>
>>>>Paul
>>>>
>>>>P.S. You could, of course, downgrade to an old PyXML release, but I
>>>>wouldn't recommend that.
>>>
>>>
> 





More information about the Python-list mailing list