2012-02-08 4 views
2

Python Web Code de service:service web Appel Python en utilisant PHP

import web 
from soaplib.wsgi_soap import SimpleWSGISoapApp 
from soaplib.service import soapmethod 
from soaplib.serializers import primitive as soap_types 

urls = ("/hello", "HelloService", 
     "/hello.wsdl", "HelloService", 
     ) 
render = web.template.Template("$def with (var)\n$:var") 



class SoapService(SimpleWSGISoapApp): 
    """Class for webservice """ 
    @soapmethod(soap_types.String,_returns=soap_types.String) 
    def hello(self,message): 
     """ Method for webservice""" 
     return "Hello world "+message 



class HelloService(SoapService): 
    """Class for web.py """ 
    def start_response(self,status, headers): 
     web.ctx.status = status 
     for header, value in headers: 
      web.header(header, value) 


    def GET(self): 
     response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response) 
     return render("\n".join(response)) 


    def POST(self): 
     response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response) 
     return render("\n".join(response)) 

app=web.application(urls, globals()) 

if __name__ == "__main__": 
    app.run() 

Code PHP:

<?php 

    @ini_set("soap.wsdl_cache_enabled", "0"); 


    $client = new SoapClient('http://localhost:8080/hello.wsdl'); 

    echo("<pre>"); 
    var_dump($client->__getFunctions()); 
    echo("</pre>"); 
    $params = array('World'); 


    try { 
     print_r($client->__soapCall('hello', $params)); 

    } catch (SoapFault $exception) { 
     echo $exception; 
    } 
?> 

Quand je lance mon code php, il rapporte des informations ci-dessous

SoapFault exception: [helloFault] hello() prend exactement 2 arguments (1 donné) dans C: \ website \ cosmétique \ src \ test02.php: 15 Trace de pile: # 0 C: \ website \ cosmétique \ src \ test02.php (15): SoapClient -> __ soapCall ('bonjour', Tableau) # 1 {main}

Comment résoudre ce problème? Merci.

+0

Pour regarder WSDL (hello.wsdl) dans ce cas est utile. Postez-le. – dmitry

Répondre

1

Vous ne savez pas exactement ce que SoapClient est exactement, mais il semble qu'il a besoin d'un autre argument. Que dit la documentation?

+0

la documentation est renvoyée à ce lien http://php.net/manual/fr/class.soapclient.php Je ne trouve aucune information utile dans cette documentation. –

+0

Pourriez-vous essayer un var_dump() au lieu de echo pour $ exception et nous donner la réponse? –

Questions connexes