python调用wcf服务 实现网站对客户端的调用
2015-08-14 13:12
696 查看
实现目标:
1.创建一个WCF服务,用于读卡。 再创建一个winform客户端程序,作为WCF的宿主。 WCF服务以 IP+端口的形式对外提供服务。
2.python中安装suds,用于解析 WCF的服务地址。
winform客户端程序中的主要代码:
python程序中的调用代码:
from suds.client import Client
def getDataTest(cu):
try:
client = Client(‘http://localhost:8002/Service1‘)
print client #结果看图1
result = client.service.ShowMess() #这个号码是办证的,拿来测试,哈哈
return JSONResponse(result)
except:
return JSONResponse(‘error’)
1.创建一个WCF服务,用于读卡。 再创建一个winform客户端程序,作为WCF的宿主。 WCF服务以 IP+端口的形式对外提供服务。
2.python中安装suds,用于解析 WCF的服务地址。
winform客户端程序中的主要代码:
[code] ServiceHost Host = new ServiceHost(typeof(WcfTest.Service1)); //绑定 System.ServiceModel.Channels.Binding httpBinding = new BasicHttpBinding(); //终结点 Host.AddServiceEndpoint(typeof(WcfTest.IService1), httpBinding, "http://localhost:8002/"); if (Host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null) { //行为 ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; //元数据地址 behavior.HttpGetUrl = new Uri("http://localhost:8002/Service1"); Host.Description.Behaviors.Add(behavior); //启动 Host.Open(); }
python程序中的调用代码:
from suds.client import Client
def getDataTest(cu):
try:
client = Client(‘http://localhost:8002/Service1‘)
print client #结果看图1
result = client.service.ShowMess() #这个号码是办证的,拿来测试,哈哈
return JSONResponse(result)
except:
return JSONResponse(‘error’)
相关文章推荐
- 零基础学python-2.21 回到我们的游戏 加入类和函数
- 零基础学python-2.21 回到我们的游戏 加入类和函数
- Python中的super()方法使用简介
- 简单实现Socks5代理(Python&C#)
- 04 Python 对象 - 《Python 核心编程》
- 零基础学python-2.19 定义函数、调用函数与默认参数
- Python: 搜狗分类语料库gb2312编码为utf-8
- python使用thrift2协议connect hbase
- 小白学python(8.14)
- python 定时器
- python hadoop 在streaming中获取文件名的方法
- Python元组
- 判断网页的编码方式 python
- python+selenium测试用例参考
- 在Eclipse中手动安装pydev插件,eclipse开发python环境配置
- python中的if __name__=='__main__': main()解析
- Python列表
- Python中文件读取readlines()方法
- python中index()与find()的区别
- Python3 ctypes简单使用