开发者

share session Asp.NET webservice - silverlight

I have a webservice that looks like this

[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Connector : System.Web.Services.WebService
    {
        private static readonly ILog log = MLogger.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


        [WebMethod(EnableSession = true)]
        public void SetSession(string session, string value)
        {
            Session[session] = value;
        }

        [WebMethod(EnableSession = true)]
        public string GetSession(string session)
        {
            string result = HttpContext.Current.Session[session] != null ? (string)HttpContext.Current.Session[session] : null;
            log.Info("GetSession :" + session +"-"+result);
            return result;
        }

    }

I have a asp.net page that contains a Silverlight application. The page sets a Session key:

 if (Session["Token"] == null)
                {
                    Session["Token"] = Token.GetToken(Connection, HttpContext.Current.Request.ServerVariables["HTTP_HOST"], "")[0].Value;
                    log.Info("Token:" + Session["Token"].ToString());
                }

the problem is that when I call the webservice from the silverlight application to get the "Token" Session value it is null.. The log looks like this:

Token:e4d46740-2bb1-4956-a27b-a1af0b908acc <-this is where the session is set
GetSession :Token- <-this is in the webservice where GetSession("Token") is called...

What did I did wrong? How can a share开发者_StackOverflow中文版 Session data with a webservice? Thanks, Bogdan


The Key you are using to store the data is the string "Token", which is a constant, while to retrieve it you are surely using some other string for the Key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜