Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have created wcf service. I m using PerSession for the InstanceContextMode.

Is it possible to manually release the instance of service created by wcf service per user request ?

Means How to terminate session of user manually by any of the WCF Service Method ?

Thanks.
Posted
Updated 12-Dec-13 19:59pm
v4

Sure.
All you have to do is mark:

C#
[OperationContract(IsInitiating=false, IsTerminating=true)]
public void CloseSession()
{

}

And session is gone...


You can also set method that's allowed to create session:

C#
OperationContract(IsInitiating=true, IsTerminating=false)]
public void StartSession()
{

}



Use google for more info. :)
 
Share this answer
 
v2
You can set the request objects to NULL and then call the [proxyclient].close() method. It will close the current session.

Also, before calling the close method, check if the service is in faulted state. if it so, call the abort method and then call the close method.

Best way is to enclose within USING block. This will ensure that the client is closed when the control completes the execution of USING block.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900