[英]how to let WCF service to send messages to the client without calling its method from the service?
Im new to WCF and what i know till now that i can use a method from WCF service and it returns some value back, but i was wondering if i used a backgroundworker and i want to send a message like "Job Complete" to the client after it got finished, how would i do that?
我是WCF的新手,直到现在我知道我可以使用WCF服务中的方法并且它返回了一些值,但是我想知道我是否使用了后台工作人员,并且想向客户端发送“ Job Complete”之类的消息完成后,我该怎么办?
Should i use AutoResetEvent and wait for the backgroundworker until completes then resetEvent.Set()
to let the method on the main thread to return the message? 我应该使用AutoResetEvent并等待backgroundworker直到完成,然后
resetEvent.Set()
才能让主线程上的方法返回消息吗?
i need that thread not to get busy, it should be ready for any other commands i request from the client. 我需要该线程不忙,应该准备好从客户端请求的任何其他命令。 so any ideas?
有什么想法吗?
I've figured it out, well i couldn't send message back from service without calling the method but when i changed the attributes of the service behavior from ConcurrencyMode = ConcurrencyMode.Single
to ConcurrencyMode = ConcurrencyMode.Multiple
it went multithreaded and the result : 我已经弄清楚了,好吧,我无法在不调用方法的情况下从服务发送回消息,但是当我将服务行为的属性从
ConcurrencyMode = ConcurrencyMode.Single
更改为ConcurrencyMode = ConcurrencyMode.Multiple
进入多线程处理后,结果是:
the method runs in a new thread because of this attribute and i can send other request while that thread is working and when it finishs it returns me the message/result. 由于该属性,该方法在新线程中运行,并且我可以在该线程工作时发送其他请求,并在该线程完成时向我返回消息/结果。
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
public class FileManagerService : IFileManager
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.