[XML-SIG] Python Web Service Client Question
Joshua Boverhof
JRBoverhof at lbl.gov
Wed Mar 24 19:06:47 EST 2004
I think this is what you want.
-josh
------------------------------------
#!/usr/bin/env python
import sys
from ZSI.client import Binding
from ZSI import TC
u = '/WebService.jws'
n = 'http://www.openuri.org/'
b = Binding(url=u, ns=n, host='localhost', port=7001, tracefile=sys.stdout)
class MyInt(int):
typecode = TC.Integer('empno')
empnum=MyInt(123)
result=b.methodName(empnum)
print result
-----------------------------------
<methodName>
<empno xsi:type="xsd:integer">123</empno>
</methodName>
-----------------------------------
Joshua M. Goldfarb wrote:
> Good afternoon,
>
> I'm trying to write a simple web service client in Python.
> The web service I'm trying to access is simple. It takes an integer
> and returns a String. For some reason, when Python serializes the
> request, I get this snippet (sanitized a bit):
>
> ....snip....
> <SOAP-ENV:Body>
> <methodName>
> <empno>
> <empno xsi:type="xsd:integer">123</empno>
> </empno>
> </methodName>
> </SOAP-ENV:Body>
> ....snip....
>
> The web service complains that it expects a simple type, and I can
> understand why, given what I pasted above.
>
> I can get Python to name the first <empno> whatever I want it to
> be named, but I can't get Python to remove it. So, I guess there are
> two approaches:
>
> 1) Figure out how to get Python to remove the outer <empno>
> 2) Name the outer <empno> something that the web service won't
> complain about (i.e., <doNotParseMe>)
>
> I can't figure out how to do either of the two approaches.
> Perhaps there is also another approach (this is only my second day
> coding in Python, though I'm already thoroughly amazed by the language).
>
> Here is the Python web service client code:
>
> from ZSI.client import Binding
> from ZSI import TC
>
> log_file = open('soaplog.txt', 'w+')
> u = '/WebService.jws'
> n = 'http://www.openuri.org/'
> b = Binding(url=u, ns=n, host='localhost', port=7001, tracefile=log_file)
>
> class MyInt:
> def __init__(self, Empno):
> self.empno=Empno
> MyInt.typecode=TC.Struct(MyInt, [TC.Integer('empno')], 'empno')
>
> empnum=MyInt(123)
>
> result=b.methodName(empnum)[0]
> print result
>
> Thanks,
>
> Josh
>
>------------------------------------------------------------------------
>
>_______________________________________________
>XML-SIG maillist - XML-SIG at python.org
>http://mail.python.org/mailman/listinfo/xml-sig
>
>
More information about the XML-SIG
mailing list