kartagis / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

Cannot pass a dictionary. #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Tried many combinaisions for 2 hours such as :
    dispatcher.register_function('get_device_list_list',
        webserv.get_device_list_list,
        returns={'Result': [{str: str}]},
        args = {})
2. Defining my client : client = SoapClient(wsdl = "http://127.0.0.1:8080/", 
trace = True)

3. I never have the answer, usually it breaks at the client definition.

What is the expected output? What do you see instead?
- Generate a message such as : 
<Result><ItemA>Value1</ItemA><ItemB>Value2</ItemB>....<ItemX>Value26</ItemX></Re
sult>
- And client parse it correctly in a dict such as 
{'ItemA': 'Value1', ... }

What version of the product are you using? On what operating system?
Version 1.02a on UbuntuS erver 10.04.

Please provide any additional information below.

Original issue reported on code.google.com by francois...@gmail.com on 21 Aug 2010 at 11:43

GoogleCodeExporter commented 8 years ago
Any news ? An other example : this is generated by pysimplesoap server, but 
impossible to decode by client :
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><get_device_det
ailsResponse><Result><56><room>Chambre1</room><name>Centre</name><posx/>
<floor>Etage</floor><posy/>
<description/>
</56><42><room>Couloir</room><name>Centre</name><posx/>
<floor>RDC</floor><posy/>
<description/>
</42><43><room>SAM</room><name>Centre</name><posx/>
<floor>RDC</floor><posy/>
<description/>
</43><115><room>Grenier</room><name>Centre2</name><posx/>
<floor>Grenier</floor><posy/>
<description/>
</115><61><room>Chambre3</room><name>Volet1</name><posx/>
<floor>Etage</floor><posy/>
<description/>
</61><117><room>Couloir</room><name>SpotSasWC</name><posx/>
<floor>RDC</floor><posy/>
<description/>
</117><63><room>Chambre2</room><name>Volet1</name><posx/>
<floor>Etage</floor><posy/>
<description/>
</63><64><room>Chambre2</room><name>Volet2</name><posx/>
<floor>Etage</floor><posy/>
<description/>
</64><49><room>RDC</room><name>Vitesse 2</name><posx/>
<floor>RDC</floor><posy/>
<description/>
</49><113><room>Salon</room><name>Centre</name><posx/>
<floor>RDC</floor><posy/>
<description/>
</113><67><room>Couloir</room><name>Sonette</name><posx/>
<floor>RDC</floor><posy/>
<description/>
</67><68><room>Salon</room><name>AppliqueVerandaD</name><posx/>
<floor>RDC</floor><posy/>
<description/>

Original comment by francois...@gmail.com on 29 Aug 2010 at 7:29

GoogleCodeExporter commented 8 years ago
Sorry for the delay, I was on vacation.

Maybe you need xsd:struct but it isn implemented yet (or use raw 
SimpleXMLElement to manually serialize that).

As a workaround, if you need something like:

{'ItemA': 'Value1', 'ItemB': 'Value', ... 'ItemX': 'Value'}

Just declare all possible keys:

dispatcher.register_function('get_device_list_list',
        webserv.get_device_list_list,
        returns={'Result': [{'ItemA': str, 'ItemB': str, ... 'ItemX': str}]},
        args = {})

If you can post some actual code or xml messages maybe we can advance more with 
this.

Original comment by reingart@gmail.com on 2 Sep 2010 at 4:45

GoogleCodeExporter commented 8 years ago
It would be nice if the framework supported all sequence and set types as well. 
The workaround does not support variable length arguments or results.

Original comment by awsmit...@gmail.com on 5 Apr 2011 at 3:32

GoogleCodeExporter commented 8 years ago
Hi, I created these function to be able to send dictionaries. Hope that will 
help you too.

On the client side, before sending your dictionnary :
    def _params_to_soap(self, params = {}):
        soap_params = []
        for key, value in params.iteritems():
            dict = {}
            dict['key'] = str(key)
            dict['value'] = str(value)
            soap_params.append({'id':dict})
        return soap_params

On the Server side :
    def _soap_to_params(self, params=[]):
        real_params = {}
        for element in params:
            real_params[element['id']['key']] = element['id']['value']
        return real_params

   def myfunct(self, arg1 = None, arg2 = 0, params=[]):
       params = self._soap_to_params(params)
       for key, value in params.iteritems(): print '%s => %s ' % (key, value)

    def run(self):
        dispatcher = SoapDispatcher('dispatcher',
                                location = location,
                                action = action, # SOAPAction
                                namespace = namespace, prefix="ns0",
                                trace = trace,
                                ns = ns)
        # register the user function
        dispatcher.register_function('myfunct', self.myfunct,
                                 returns={'myfuncResult': int}, args={'arg1': str,'arg2': int, 'params':[{'id':{'key':str,'value':str}}]}) #params is the dictionnary

        print "Starting server..."
        httpd = HTTPServer(("", 8008), SOAPHandler)
        httpd.dispatcher = dispatcher
        httpd.serve_forever()

Original comment by christop...@gmail.com on 7 Feb 2012 at 1:32

GoogleCodeExporter commented 8 years ago
Christophe,
Could you provide an example of your client side function?
    def _params_to_soap(self, params = {}):
        soap_params = []
        for key, value in params.iteritems():
            dict = {}
            dict['key'] = str(key)
            dict['value'] = str(value)
            soap_params.append({'id':dict})
        return soap_params

Say you want to send in {Name:1000}

Original comment by shaunth...@gmail.com on 13 Feb 2014 at 12:45