When duplex communication is implemented, the service end adopts this method.
Code
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. paiepublicchatinfo (E. fromperson, E. Chat );
Break;
Case messagetype. leave:
_ Callback. userleave (E. fromperson );
_ Callback. getonlineuser (this. getonlineperson ());
Break;
Case messagetype. privatechat:
_ Callback. paieprivatechatinfo (E. fromperson, E. toperson, E. Chat );
Break;
}
}
In case messagetype. Enter: There are two callback client Methods: userenter and getonlineuser. Then the client calls the following method:
Using (chatclient chat = new chatclient (New instancecontext (this), "dualendpoint "))
{
Personinfo info = new personinfo ();
Info. Age = 27;
Info. Name = textbox2.text;
Info. Sex = "male ";
Chat. contect (Info );
}
When the service is started, the following error is reported in the getonlineuser callback method on the server:
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.
My idea should be like this:
The session should be dispose after the server calls back and executes userenter. Therefore, the above error will be reported during subsequent getonlineuser execution.
The solution is as follows::
I added isinitiating = true to the operationcontract feature of the Connect Method of the interface.
[Operationcontract (isoneway = true, isinitiating = true)]
Void contect (personinfo info );
Then, add isterminating = true to the operationcontract feature of the getonlineuser method in the callback interface.
[Operationcontract (isoneway = true, isterminating = true)]
Void getonlineuser (list <personinfo> list );
The client code is changed:
Code
Chatclient chat = new chatclient (New instancecontext (this), "dualendpoint ");
Personinfo info = new personinfo ();
Info. Age = 27;
Info. Name = textbox2.text;
Info. Sex = "male ";
Chat. contect (Info );
Restart the instance and check the result again. An error is returned:
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.
Error message: Add sessionmode property and set it to sessionmode. required, OK, add,
[Servicecontract (namespace = "http://cyclonechat.com/", callbackcontract = typeof (icallback), sessionmode = sessionmode. Required)]
Public interface iChat
Start again. OK. All done!