c#客户端向 PYTHON SOAPLIB+WEB.PY 通信问题

fatlity 2011-06-17 12:57:52
现象:c#客户端获取不到服务器端的返回值,一直是null

c#客户端代码

//添加web引用http://127.0.0.1:8080/hello.wsdl为WS
WS.HelloService ws = new PYBETEST.WS.HelloService();
WS.hello inp = new PYBETEST.WS.hello();
inp.message = "me";
WS.helloResponse re = ws.hello(inp);
//re为null


python服务端代码

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 """

#__tns__ = 'http://test.com'

@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()



用python客户端可以取得返回值
python客户端代码

from soaplib.client import make_service_client
from testServer import HelloService

client = make_service_client('http://localhost:8080/hello', HelloService())
a= client.hello('me')
print a

#Hello world me


难道c#调用python的webservice需要什么特殊的方法吗?
...全文
109 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
iambic 2011-06-20
  • 打赏
  • 举报
回复
先抓包看下。看返回的http xml里是不是正确的。如果是正确的,就是客户端的问题,否则就是服务器端的问题。先大概定位下吧。另外看下生成的wsdl,可以贴出来看下。别的建议想不出来。
panghuhu250 2011-06-20
  • 打赏
  • 举报
回复
[Quote=引用楼主 fatlity 的回复:]
#客户端代码
C# code

//添加web引用http://127.0.0.1:8080/hello.wsdl为WS
WS.HelloService ws = new PYBETEST.WS.HelloService();
WS.hello inp = new PYBETEST.WS.hello();
inp.message = "me";
WS.helloResponse re = ws.hello(inp);
//re为null
[/Quote]

不熟悉C#,不过在上面的代码中你的代码是怎么设定service地址为http://127.0.0.1:8080/hello.wsdl的?

37,722

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧