[Fedora-suds-list] suds client and soaplib

Jeff Ortel jortel at redhat.com
Wed Apr 14 13:10:20 UTC 2010


Hey John,

In example #1 you are invoking the method properly. The method signature (according to 
suds) is defined as:

say_hello(xs:string name, xs:integer times, )

So, you should pass 2 simple types.

Unless the wsdl has changed between example #1 & #2, you are invoking say_hello() 
incorrectly in #2.  One of the value adds of suds is that it provides a very consistent, 
RPC-like API to the user that is independent of the soap envelope messaging styles.

By doing:

client.factory.create("ns0:say_hello")

You are passing an object that is an implementation detail of the soap envelope for 'name' 
when suds expects a string.

If you had defined you service in soaplib to take an object of class 'Hello':

class Hello:
   def __init__(self, name, times):
     self.name = name
     self.times = times

def say_hello(hello):
   ...

I believe the wsdl would be generated such that suds would show the signature as something 
like:

say_hello(ns0:Hello hello,)

In this case you would pass hello as an object.

hello = client.factory.create('ns0:Hello')
hello.name = 'john'
hello.times = 10

-or-

hello = { 'name':'john', 'times':10 }

client.service.say_hello(hello)


Hope this helps,

Jeff


On 04/13/2010 03:18 PM, John Aherne wrote:
> I am using the soaplib trivial helloworld.py example.
> I can call soaplib from suds using simple types as the first example
> shows below.
> I pass 2 simple types a name and an integer value. And I get the
> response repeated the number of times of the integer value.
>
> But I am having a problem with calling soaplib from suds using the
> client.factory_create method.
> This you can see in the 2nd example.
> Looking at the log output it seems that it is SUDS that has the problem
> - but I am no expert on this.
> It looks like it is trying to create a structure for a complex type and
> to me it seems like it is not doing it correctly.
> It could be I'm doing this all wrong. And I should be sticking to
> avoiding the client factory for this type of message.
> But I thought I would check and see if someone can give me some pointers
> as to what I should be doing.
>
> Needless to say I am not that well up in soap messages
>
> Thanks for any info
>
> John Aherne
>
>
> ************************************
> 1st example
> ************************************
>
> from suds.client import Client
> import logging
> logging.basicConfig(level=logging.INFO)
> logging.getLogger('suds.client').setLevel(logging.DEBUG)
> client= Client("http://localhost:7889/wsdl",cache=None)
> print client
> print client.service.say_hello("punk",5)
>
> E:\soaplib-0.8.1\examples>test_suds.py
>
> Suds ( https://fedorahosted.org/suds/ )  version: 0.3.9 GA  build:
> R659-20100219
>
>
> Service ( HelloWorldService ) tns="HelloWorldService.HelloWorldService"
>     Prefixes (1)
>        ns0 = "HelloWorldService.HelloWorldService"
>     Ports (1):
>        (HelloWorldService)
>           Methods (1):
>              say_hello(xs:string name, xs:integer times, )
>           Types (3):
>              say_hello
>              say_helloResponse
>              stringArray
>
>
> DEBUG:suds.client:sending to (http://localhost:7889/wsdl)
> message:
> <SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:n
> s1="HelloWorldService.HelloWorldService"
> xmlns:xsi="http://www.w3.org/2001/XMLSc
> hema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Header/>
> <ns0:Body>
> <ns1:say_hello>
> <name>punk</name>
> <times>5</times>
> </ns1:say_hello>
> </ns0:Body>
> </SOAP-ENV:Envelope>
> DEBUG:suds.client:headers = {'SOAPAction': u'"say_hello"',
> 'Content-Type': 'text
> /xml'}
> DEBUG:suds.client:http succeeded:
> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
> xmlns:S
> OAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><say_helloRes
> ponse><say_helloResult type="tns:stringArray"><string
> xsi:type="xs:string">Hello
> , punk</string><string xsi:type="xs:string">Hello, punk</string><string
> xsi:type
> ="xs:string">Hello, punk</string><string xsi:type="xs:string">Hello,
> punk</strin
> g><string xsi:type="xs:string">Hello,
> punk</string></say_helloResult></say_hello
> Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
> WARNING:suds.umx.typed:attribute (type) type, not-found
> (stringArray){
>     _type = "tns:stringArray"
>     string[] =
> "Hello, punk",
> "Hello, punk",
> "Hello, punk",
> "Hello, punk",
> "Hello, punk",
>   }
>
> *********************************
> 2nd Example
> ********************************
>
> from suds.client import Client
> import logging
> logging.basicConfig(level=logging.INFO)
> logging.getLogger('suds.transport').setLevel(logging.DEBUG)
> client= Client("http://localhost:7889/wsdl",cache=None)
> print 'myclient',client
> e = client.factory.create("ns0:say_hello")
> print ' i am E',e
> e.name <http://e.name> = "punk"
> e.times = 3
> print 'I am E 2',e
> client.service.say_hello(e)
>
>
> E:\soaplib-0.8.1\examples>test_suds2.py
> DEBUG:suds.transport.http:opening (http://localhost:7889/wsdl)
> mycleint
> Suds ( https://fedorahosted.org/suds/ )  version: 0.3.9 GA  build:
> R659-20100219
>
>
> Service ( HelloWorldService ) tns="HelloWorldService.HelloWorldService"
>     Prefixes (1)
>        ns0 = "HelloWorldService.HelloWorldService"
>     Ports (1):
>        (HelloWorldService)
>           Methods (1):
>              say_hello(xs:string name, xs:integer times, )
>           Types (3):
>              say_hello
>              say_helloResponse
>              stringArray
>
>
>   i am E (say_hello){
>     name = None
>     times = None
>   }
> I am E 2 (say_hello){
>     name = "punk"
>     times = 3
>   }
> DEBUG:suds.transport.http:sending:
> URL:http://localhost:7889/wsdl
> HEADERS: {'SOAPAction': u'"say_hello"', 'Content-Type': 'text/xml',
> 'Content-typ
> e': 'text/xml', 'Soapaction': u'"say_hello"'}
> MESSAGE:
> <SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:n
> s1="HelloWorldService.HelloWorldService"
> xmlns:xsi="http://www.w3.org/2001/XMLSc
> hema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Header/>
>
> ****************************************
> his I think shows the problem
> ****************************************
> <ns0:Body>
> <ns1:say_hello>
> <name>
> <name>punk</name>
> <times>3</times>
> </name>
> <times/>
> </ns1:say_hello>
> </ns0:Body>
>
> ************************************************
>
> </SOAP-ENV:Envelope>
> ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:n
> s1="HelloWorldService.HelloWorldService"
> xmlns:xsi="http://www.w3.org/2001/XMLSc
> hema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Header/>
> ******************************************
> This I think shows the problem
> *****************************************
>
> <ns0:Body>
> <ns1:say_hello>
> <name>
> <name>punk</name>
> <times>3</times>
> </name>
> <times/>
> </ns1:say_hello>
> </ns0:Body>
>
>
> </SOAP-ENV:Envelope>
> Traceback (most recent call last):
>    File "E:\soaplib-0.8.1\examples\test_suds2.py", line 13, in <module>
>      client.service.say_hello(e)
>    File "E:\python-suds-0.3.9\suds\client.py", line 539, in __call__
>      return client.invoke(args, kwargs)
>    File "E:\python-suds-0.3.9\suds\client.py", line 598, in invoke
>      result = self.send(msg)
>    File "E:\python-suds-0.3.9\suds\client.py", line 633, in send
>      result = self.failed(binding, e)
>    File "E:\python-suds-0.3.9\suds\client.py", line 684, in failed
>      r, p = binding.get_fault(reply)
>    File "E:\python-suds-0.3.9\suds\bindings\binding.py", line 238, in
> get_fault
>      raise WebFault(p, faultroot)
> suds.WebFault: Server raised fault: 'range() integer end argument
> expected, got
> NoneType.'
>
> E:\soaplib-0.8.1\examples>
>
>
>
> _______________________________________________
> suds mailing list
> suds at lists.fedoraproject.org
> https://admin.fedoraproject.org/mailman/listinfo/suds

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5126 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.fedoraproject.org/pipermail/suds/attachments/20100414/466b41b3/attachment.bin 


More information about the suds mailing list