在单独的线程上托管WCF [英] Host WCF on a separate thread

查看:74
本文介绍了在单独的线程上托管WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个单独的线程上托管一个WCF。将有一个Windows应用程序将与此WCF通信。 WCF将托管在这个Windows应用程序中,此Windows应用程序的UI线程将与工作线程中托管的此WCF进行通信。



WCF将是一个名为的双工管道。



如何实现此WCF的UI线程和工作线程之间的通信?

解决方案

< blockquote>似乎有必要在WCF服务中使用多线程:



http://stackoverflow.com/questions/1836402/threads-in-wcf-service [ ^ ]



如果该剂量回答你的问题,你应该开始在WCF上阅读Microsoft的文档,你可以在这里找到:

http: //msdn.microsoft.com/ en-us / netframework / aa663324.aspx [ ^ ]



祝您好运:)


在另一个线程中启动并使用事件,和servicehost的单例模式。

订阅ServiceHost的事件 - 然后你可以随意编组到用户界面。

我假设你想要一些不同的行为在您的服务主机之外,然后只是客户端请求和回复,客户端调用ServiceHost并发送重放,但如果您的应用程序是客户端他自己托管,那么主机运行的线程无关紧要。如果在另一方面,您希望您的winform应用程序访问服务主机,这将是不同的 - 最简单的方法是让您的服务主机订阅您的应用程序中的事件。封装它将您的数据传递到表单事件的服务主机订阅中,它应该为您完成。


I want to host a WCF on a separate thread. There will be a windows application which will communicate with this WCF. The WCF will be hosted inside this windows application and UI thread of this windows application will communicate with this WCF hosted in a worker thread.

WCF will be a duplex with named pipes.

How do I achieve the communication between the UI thread and worker thread of this WCF?

解决方案

Is dosent seem to be necessary to have use multithreading in WCF services:

http://stackoverflow.com/questions/1836402/threads-in-wcf-service[^]

If that dosent answer your question you should start reading the documentation from Microsoft on WCF, whitch you could find here:
http://msdn.microsoft.com/en-us/netframework/aa663324.aspx[^]

So good luck to you :)


Start it in another thread and use events, and the singleton pattern for your servicehost.
Subscribe to the events of your ServiceHost - you can then marshall to the UI as you please.
I assume you want some different behavior out of your Service Host then just a client request and reply, the client calls the ServiceHost and the replay is sent, but if your application is being a client tot he host itself it will not matter what thread the host is running in. If on the other hand you want your winform application to access the service host, that would be different - , the easiest is to have your service host subscribe to events in your application. Encapsulate it pass in your data into the Service Host subscription to the form event and it should do the trick for you.


这篇关于在单独的线程上托管WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆