简体   繁体   English

双向WCF服务通信

[英]Two sided WCF services communication

I'm using WCF. 我正在使用WCF。

I have two applications: "Main" and "Worker". 我有两个应用程序:“Main”和“Worker”。

Sometimes application "Main" is giving task for "Worker". 有时应用程序“Main”为“Worker”提供任务。 "Worker" is doing work and when work is done it gives result to "Main". “工人”正在做工作,当工作完成时,它会将结果给予“主要”。

How should this communication be done? 这个沟通应该如何进行?

I need to call Worker.AddTask(Task) from Main and Main.AddResult(Result) from Worker. 我需要从Main调用Worker.AddTask(Task),从Worker调用Main.AddResult(Result)。 Is there better way than setting up two Services? 有没有比设置两个服务更好的方法?

Does every call to "Worker" eventually end with a result for "Main" to work with? 对“工人”的每次调用最终都会以“主要”的结果来结束吗? If so, you might want to just have "Main" call "Worker" asynchronously, the "Main" can just wait for the results as then come back. 如果是这样,你可能只想让“Main”异步调用“Worker”,“Main”可以等待结果然后再返回。 See: http://msdn.microsoft.com/en-us/library/ms730059.aspx 请参阅: http//msdn.microsoft.com/en-us/library/ms730059.aspx

This sounds classic for WCF's callbacks- it allows for two-way async communication between server and client (in your case, the server would be the 'worker', and the 'main' application would invoke its methods in order to start processing. When worker is done, it will invoke a callback on main.) 对于WCF的回调来说这听起来很经典 - 它允许服务器和客户端之间的双向异步通信(在您的情况下,服务器将是'worker','main'应用程序将调用其方法以便开始处理。 worker已完成,它将在main上调用回调。)
LMGTFY :) LMGTFY :)

Assuming two applications are separate processes and communicating over services... 假设两个应用程序是独立的进程并通过服务进行通信......

I think you may use netTcpBinding and Callback contracts 我想你可以使用netTcpBindingCallback合约

This requires two way communication between the two components. 这需要两个组件之间的双向通信。 The first link I'm providing is the description in MSDN and the second link points to an implementation example. 我提供的第一个链接是MSDN中的描述,第二个链接指向实现示例。 Enjoy. 请享用。

MSDN Article MSDN文章

Example Link 示例链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM