开发者

wcf (webhttpbinding) calling via jquery - asp.net session not populated

I'm farily new to wcf and was hoping someone could help. I have a wcf project and a web app. Wcf project is hosted as an app in IIS in the web project both using the same app pool.

I've added sessionmode.allowed to my wcf interface, enabled aspnetcompatibilitymode. For the binding i've set transport as the security and have tried allowcookies as false and true.

When i hit the site and check keys in the session there's about 5, however when it then c开发者_运维知识库alls via jquery to my service and i check keys in the session there is none. It seems like the cookies aren't getting sent for every request.

Has anyone experienced similar behaviour?

Thanks


I wasn't even aware that that was possible, so I just set up my own test project. And session state worked fine for me.

If it helps, here is the code I wrote that works:

using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
    [OperationContract]
    [WebGet]
    public string DoWork()
    {
        var httpContext = HttpContext.Current;
        var sessionState = httpContext.Session;

        return (string)sessionState["Foo"]; // This returns "Bar"
                                            // which I set in the Page_Load 
                                            // server method
    }
}

An in my default page's Load method:

protected void Page_Load(object sender, EventArgs e)
{

    System.Web.SessionState.HttpSessionState sessionState = this.Session;
    sessionState["Foo"] = "Bar";
}

And in my web.config file:

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MyServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment 
           aspNetCompatibilityEnabled="true" 
           multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="MyService">
        <endpoint 
              address="" 
              behaviorConfiguration="MyServiceAspNetAjaxBehavior"
              binding="webHttpBinding" 
              contract="MyService"/>
      </service>
    </services>
  </system.serviceModel>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜