views:

150

answers:

3

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
Thank you for reply, but my special case needs a lot of Session value settings and its practicaly impossible through parameter
Throjen
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
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
Can we take Session values from SessionId if we share the asp.net session Id to WCF service through any parameter???
Throjen
No, it needs to be passed as cookie along the SOAP request.
Darin Dimitrov
ooopps, its cracking ..ofcourse microsoft might have made an alternative for existing systems :( anyways, thank you for suggestions :)
Throjen
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
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
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