2 wjl2757 wjl2757 于 2014.10.30 15:57 提问

关于Win7 下 Python写WebService问题

#!/usr/bin/python

-*- coding: utf-8 -*-

import soaplib
import unittest
from soaplib.core.util.wsgi_wrapper import run_twisted #发布服务
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
from soaplib.core import Application

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):
return str(a)+'+'+str(b)+'='+str(a+b)

@soap(_returns=Array(String))
def GetCdrArray(self):
L_Result=["1","2","3"]
return L_Result
@soap(_returns=C_ProbeCdrModel)
def GetCdr(self): #返回的是一个类,该类必须是ClassModel的子类,该类已经在上面定义
L_Model=C_ProbeCdrModel()
L_Model.Name=L_Model.Name
L_Model.Id=L_Model.Id
return L_Model

def startservice():
try:
print u'服务已经开启'
from wsgiref.simple_server import make_server
soap_application = Application([AdditionService], 'tns')
print 'soap_application'
wsgi_application = wsgi.Application(soap_application)
server = make_server('localhost', 7789, wsgi_application)
print 'end'
server.serve_forever()

    except Exception,e:
            print 'error',e

if name=='__main__': #发布服务

startservice()

代码贴出来,
运行到soap_application = Application([AdditionService], 'tns')时 就停止了 ,不往下走了,也不报错。

Csdn user default icon
上传中...
上传图片
插入图片