python开发webservice例子
服务器段代码:
import soaplib from soaplib.core.server import wsgi from soaplib.core.service import DefinitionBase from soaplib.core.service import soap from soaplib.core.model.clazz import Array from soaplib.core.model.clazz import ClassModel from soaplib.core.model.primitive import Integer,String class C_ProbeCdrModel(ClassModel): __namespace__ = "C_ProbeCdrModel" Name=String Id=Integer class AdditionService(DefinitionBase): #this is a web service @soap(Integer,Integer,_returns=String) def addition(self,a,b): print 'aaaaaaaaaaaa' return str(a)+'+'+str(b)+'='+str(a+b) @soap(_returns=Array(String)) def GetCdrArray(self): print 'bbbbbbbbbb' L_Result=["1","2","3"] return L_Result @soap(_returns=C_ProbeCdrModel) def GetCdr(self): print 'ccccccc' L_Model=C_ProbeCdrModel() L_Model.Name=L_Model.Name L_Model.Id=L_Model.Id return L_Model if __name__=='__main__': try: print 'service start' from wsgiref.simple_server import make_server soap_application = soaplib.core.Application([AdditionService], 'tns') wsgi_application = wsgi.Application(soap_application) server = make_server('localhost', 7789, wsgi_application) server.serve_forever() except ImportError: print 'error'
客户端代码:
__author__ = 'admin' from suds.client import Client test=Client('http://localhost:7789/SOAP/?wsdl') print test
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!