微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Windows窗体应用程序中托pipeWCF服务

我需要在Windows窗体应用程序中托pipeWCF服务,并从Windows服务调用WCF服务,该服务将数据发送到WCF服务,WCF服务将在Windows窗体应用程序(桌面应用程序)中显示它。

我怎样才能实现呢? 我需要以前正确工作的代码

从内存加载运行时的animation光标

subprocess上重叠的ReadFileEx'redirect标准输出不会触发

用应用程序绑定Windows Mono运行时

通过Anaconda在Windows上为Python安装`opencv_contrib`

如何停止作为Windows服务运行的web.py服务器

这段代码应该足以让你开始:

Form1.cs的

namespace TestWinform { public partial class Form1 : Form { private ServiceHost Host; public Form1() { InitializeComponent(); } private void Form1_Load(object sender,EventArgs e) { Host = new ServiceHost(typeof(MyWcfService)); Host.open(); } private void Form1_FormClosed(object sender,FormClosedEventArgs e) { Host.Close(); } } }

App.config

<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="TestWinform.MyWcfServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="TestWinform.MyWcfServiceBehavior" name="TestWinform.MyWcfService"> <endpoint address="" binding="wsHttpBinding" contract="TestWinform.IMyWcfService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:8080/MyWcfService/" /> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration>

请注意,当我向项目中添加一个WCF服务时,Visual Studio生成了App.config

我建议你也使用一个线程:

private void Form1_Load(object sender,EventArgs e) { Task.Factory.StartNew(() => { host = new ServiceHost(typeof(AssinadorWcf.AssinadorDigitalLecom)); host.open(); }); } private void Form1_FormClosed(object sender,FormClosedEventArgs e) { try { host.Close(); } catch { } }

使用下面的代码来承载Windows窗体应用程序中的WCF服务:

using System.ServiceModel.Channels; ServiceHost host = new ServiceHost(typeof(MyNamespace.OrderService)); BindingElementCollection bec = new BindingElementCollection(); SymmetricSecurityBindingElement ssbe = new SymmetricSecurityBindingElement(); ssbe.LocalServiceSettings.InactivityTimeout = new TimeSpan(0,10,0); bec.Add(ssbe); bec.Add(new TextMessageEncodingBindingElement()); bec.Add(new HttpsTransportBindingElement()); CustomBinding customBinding = new CustomBinding(bec); host.AddServiceEndpoint(typeof(MyNamespace.IOrderService),customBinding,"http://localhost:8000/O rderService/");

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐