本文介绍了双工服务的实例、会话和并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,即服务应该每秒向客户端发送一条消息.服务只能有一个客户端.

I have a requirement where a service should be sending a message to client every second. There can be only one client to the service.

我创建了一个双工服务,现在对服务的实例、并发和会话感到困惑.

I have a created a duplex service and now confused on instance, concurrency and session for the service.

  1. 双工服务是否总是需要会话?SessionMode.Required

  1. Is session always required for a duplex service? SessionMode.Required

InstanceContextMode 是否应该始终为 PerSession.InstanceContextMode = InstanceContextMode.PerSession?

Does the InstanceContextMode should always be PerSession. InstanceContextMode = InstanceContextMode.PerSession?

ConcurrencyMode 应该是什么?

What should be the ConcurrencyMode?

如何防止额外的客户端连接到服务.客户端中的回调引用是否应该是静态的,并在最初收到客户端请求时检查空引用.

How can I prevent additional client connection to the service. Should the callback reference in teh client be static and check for null reference when client request is initially received.

我将实施心跳操作来检查服务的可用性.这应该是单向调用还是请求回复调用,并且这个调用会在同一个会话中吗?

I’ll be implementing a heartbeat operation to check the availablity of the service. Should this be a one-way or request reply call and would this call be in same session?

谢谢.

推荐答案

可能是我迟到了几个月...如果你只有一个客户端并且以后不会有更多客户端,你可以使用最简单的设置: InstanceContextMode.Singleton, SessionMode.NotAllowed.

May be I'm late for a few month... If you have only one client and will not have more clients in future, you can use simplest settings: InstanceContextMode.Singleton, SessionMode.NotAllowed.

关于 ConcurrencyMode,您可以在本教程中阅读:http://codeidol.com/csharp/wcf/Concurrency-Management/Service-Concurrency-Mode/

About ConcurrencyMode you can read in this tutorial: http://codeidol.com/csharp/wcf/Concurrency-Management/Service-Concurrency-Mode/

这篇关于双工服务的实例、会话和并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 13:42