Asd*_*dfg 3 asp.net session wcf jquery
我试图在WCF服务中访问asp.net会话.我正在jQuery AJAX从我的asp.net应用程序调用wcf服务.我已经通过许多SO问题和文章,并尝试了他们所说的一切,但我仍然无法访问wcf服务中的客户端会话.当我写作时DataSet ds = HttpContext.Current.Session["data"] as DataSet;,ds总是为空.
我在这里失踪了什么?
这就是我的WCF服务的样子://接口
[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface IMyService
{
[OperationContract(IsInitiating=true)]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string GetData();
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
bool SaveData(string data);
}
Run Code Online (Sandbox Code Playgroud)
//服务
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MyService : IMyService
{
public string GetData()
{
return "something";
}
public bool SaveData(string data)
{
DataSet ds = HttpContext.Current.Session["data"] as DataSet;
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我创建的数据集session_start的Global.asax,并把它在会议上,这样我可以在整个应用程序,只要用户会话是有效的使用它.
protected void Session_Start(object sender, EventArgs e)
{
DataSet ds = new DataSet();
//Table to hold Product Selection
DataTable dt = new DataTable("T1");
dtSSNCertification.Columns.Add("Col1");
ds.Tables.Add(dt);
Session.Add("data", ds);
}
Run Code Online (Sandbox Code Playgroud)
这就是我的wcf项目的web.config bindings样子:
<service name="MyService">
<endpoint address="" behaviorConfiguration="JSONPBehaviorConfiguration"
binding="customBinding" bindingConfiguration="jsonpBinding"
contract="IMyService">
</endpoint>
</service>
Run Code Online (Sandbox Code Playgroud)
<customBinding>
<binding name="jsonpBinding" >
<jsonpMessageEncoding />
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
要使用ASP.NET功能,您需要启用与WCF的ASP.NET兼容性.在你的web.config中设置:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2078 次 |
| 最近记录: |