I recently converted my ASMX service to WCF to take advantage of the sessions.
I looked through some of the training sessions on MSDN, but still not sure if I have a good setup in my code. this works for now, but I'm not quite sure why.
I got
[ServiceContract
(SessionMode = SessionMode.Required,
Namespace = "http://smartshopservice.org")]
Then i have
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class SmartShopService : SmartShopInterface
{
private static Shopper sh = new Shopper();
private List<aaa> data = new List<aaa>();
The first part of my question is whether Shopper are my "global" variables. I want him to always be there, while everything else, such as "data", was initiated per session. I also configured WebConfig accordingly. Anything else I need to do?
My second question is how to close the session and then reset all these variables? My client is now a web client, he communicates as follows:
static GarfieldService.SmartShopInterfaceClient service
= new GarfieldService.SmartShopInterfaceClient();
, , onbody = "" ASP.NET, , :
[WebMethod]
public static bool Connect() {
try {
if (service.State
== System.ServiceModel.CommunicationState.Closed) {
service.Open();
return true;
}
else if (service.State
== System.ServiceModel.CommunicationState.Created) {
service.Open();
return true;
}
}
catch {}
return false;
}
, , ?