关于PerSession下一些方法调用的注意事项

我在实现双工通讯duplex的时候,service端由这样的一个方法
ExpandedBlockStart.gif 代码
public   void  GetPeronBehavior( object  sender, ChatEventArgs e)
        {
            MessageType type 
=  e.MessageType;
            
switch  (type)
            {
                
case  MessageType.Enter:
                    _callBack.UserEnter(e.FromPerson);
                    _callBack.GetOnlineUser(
this .GetOnlinePerson());
                    
break ;
                
case  MessageType.PublicChat:
                    _callBack.ReceivePublicChatInfo(e.FromPerson, e.Chat);
                    
break ;
                
case  MessageType.Leave:
                    _callBack.UserLeave(e.FromPerson);
                    _callBack.GetOnlineUser(
this .GetOnlinePerson());
                    
break ;
                
case  MessageType.PrivateChat:
                    _callBack.ReceivePrivateChatInfo(e.FromPerson, e.ToPerson, e.Chat);
                    
break ;
            }
        }

 

其中在case MessageType.Enter:中有两个回调客户端的方法UserEnter和GetOnlineUser,然后客户端这样调用:

 

  using  (ChatClient chat  =   new  ChatClient( new  InstanceContext( this ),  " dualendpoint " ))
            {

                PersonInfo info 
=   new  PersonInfo();
                info.Age 
=   27 ;
                info.Name 
=  textBox2.Text;
                info.Sex 
=   " " ;
                chat.Contect(info);
            }

 

然后启动服务调用的时候,在服务端回调的方法GetOnlineUser除报错:

The sequence has been terminated by the remote endpoint. The user of the remote endpoint's reliable session expects no more messages and a new message arrived. Due to this the reliable session cannot continue. The reliable session was faulted.

我的想法应该是这样的:

session应该是在服务端回调执行完UserEnter后session被dispose了。所以后续的GetOnlineUser执行的时候就会报上面的错误。

 

解决方案如下

我在接口的connect方法上的OperationContract特性中加入IsInitiating=true

 

[OperationContract(IsOneWay = true,IsInitiating=true)]

void Contect(PersonInfo info);

然后在回调接口中的GetOnlineUser方法上的OperationContract特性中加入IsTerminating=true

[OperationContract(IsOneWay = true,IsTerminating=true)]
        void GetOnlineUser(List<PersonInfo> list);

客户端的代码改为:

 

ExpandedBlockStart.gif 代码
ChatClient chat  =   new  ChatClient( new  InstanceContext( this ),  " dualendpoint " );
                PersonInfo info 
=   new  PersonInfo();
                info.Age 
=   27 ;
                info.Name 
=  textBox2.Text;
                info.Sex 
=   " " ;
                chat.Contect(info);

 

 

重启启动再看结果,还是报错:

The contract 'IChat' is not self-consistent -- it has one or more IsTerminating or non-IsInitiating operations, but it does not have the SessionMode property set to SessionMode.Required.  The IsInitiating and IsTerminating attributes can only be used in the context of a session.

 

错误提示要加入SessionMode property 然后设置为 SessionMode.Required,ok,加入,

 [ServiceContract(Namespace = "http://cyclonechat.com/", CallbackContract = typeof(ICallBack),SessionMode=SessionMode.Required)]
 public interface IChat

再启动,Ok,大功告成!

 

 

 

 

转载于:https://www.cnblogs.com/JackFeng/archive/2010/07/27/1785914.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值