【发布时间】:2011-06-16 13:58:19
【问题描述】:
我有一个看起来像这样的网络服务
[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;
}
}
我有一个包含 Silverlight 应用程序的 asp.net 页面。 该页面设置了一个 Session 密钥:
if (Session["Token"] == null)
{
Session["Token"] = Token.GetToken(Connection, HttpContext.Current.Request.ServerVariables["HTTP_HOST"], "")[0].Value;
log.Info("Token:" + Session["Token"].ToString());
}
问题是,当我从 silverlight 应用程序调用 web 服务以获取“令牌”会话值时,它为空.. 日志如下所示:
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...
我做错了什么?如何与 web 服务共享会话数据? 谢谢, 波格丹
【问题讨论】:
标签: asp.net web-services silverlight-4.0