首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python调用wcf服务 实现网

python调用wcf服务 实现网

作者头像
py3study
发布2020-01-13 15:51:21
1.7K0
发布2020-01-13 15:51:21
举报
文章被收录于专栏:python3python3python3

实现目标: 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’)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档