python调用wcf服务 实现网站对客户端的调用

实现目标:
1.创建一个WCF服务,用于读卡。 再创建一个winform客户端程序,作为WCF的宿主。 WCF服务以 IP+端口的形式对外提供服务。
2.python中安装suds,用于解析 WCF的服务地址。

winform客户端程序中的主要代码:

            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’)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值