Im using asp.net website with WCF service, having wsHttpBinding,Aspnet compatibility enabled, specified as Sessionmode -allowed, service behavior- isinitiated and client session cookie enabled. Its looking like Asp.Net session object and WCF Session( HTTPContext.Current.Session) work independently. How can I share Asp.net Session value to WCF Session and vise versa.
A:
Instead of making your web service dependent on the hosting environment I would suggest you adding the needed parameter to the operation contract so that it is passed by the consumer which in your case is an ASP.NET application that will fetch it from the session.
Darin Dimitrov
2010-05-27 06:09:05
Thank you for reply, but my special case needs a lot of Session value settings and its practicaly impossible through parameter
Throjen
2010-05-27 06:12:50
If your service is so tightly coupled to your application why creating it in the first place? For them to share the same session the service needs to be hosted in the same application pool and virtual directory as the application. Then you need to include the ASPSession_Id cookie along with the request and the service might be able to read session data but once again I would strongly discourage you from doing so. You may look at this post: http://www.sajay.com/post/2006/08/03/Using-a-Session-in-WCF-through-AspNetCompatibility.aspx
Darin Dimitrov
2010-05-27 06:18:25
Yes, I gone through that, I have already implimented what he says and still its not working. My issue is like I am converting an existing Webservice.asmx to WCF which has hell lot of session dependency.. for the moment I cant avoid that bcz existing applications are consuming it.. I appreciate if u have seen any such reference in net
Throjen
2010-05-27 06:38:08
Can we take Session values from SessionId if we share the asp.net session Id to WCF service through any parameter???
Throjen
2010-05-27 06:40:20
No, it needs to be passed as cookie along the SOAP request.
Darin Dimitrov
2010-05-27 06:50:43
ooopps, its cracking ..ofcourse microsoft might have made an alternative for existing systems :( anyways, thank you for suggestions :)
Throjen
2010-05-27 06:53:47
A:
in your service interface:
[ServiceContract]
public interface IService
{
[OperationContract]
string GetSessionValue();
[OperationContract]
void SetSessionValue(string value);
}
in your svc:
public class Service1 : IService
{
public string GetSessionValue()
{
return "your value";
}
public void SetSessionValue(string value)
{
// your code here
}
}
and finally consume that method from web code behind.
Jeaffrey Gilbert
2010-05-27 06:27:15
good , that is an idea, but I have hundreds of session values to get and set..setting these values for each service call not good, that is, to call a service method, I have to call these two methods every time..:(
Throjen
2010-05-27 06:47:02
A:
I searched a lot but could not find a way. Only option I found is use cookie enabled service in same virtual directory. Better to keep it as RESTful service
Throjen
2010-06-09 10:32:52