ASP.NET 中的 WCF 无法使用状态服务器

发布于 2024-12-11 03:23:55 字数 1798 浏览 0 评论 0原文

我在 ASP.NET 中托管 WCF 服务。 WCF 服务的大多数操作都需要 cookie。如果 ASP.NET 会话状态为“InProc”,则它可以正常工作。但是,我们希望将应用程序移动到网络农场和网络农场。我想在专用机器上运行状态服务。当我这样做时,WCF 方法不会生成 cookie。

有什么想法吗?

添加cookie的代码:

WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.SetCookie] = "myCookie" + MyVal.ToString();

WCF配置:

<system.serviceModel>

<bindings>
  <webHttpBinding>
    <binding name="secure">
      <security mode="Transport" />          
    </binding>
    <binding name="basic"></binding>                 
  </webHttpBinding>
</bindings>

<services>
  <service name="MyService" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="MyService.Interface" behaviorConfiguration="web" bindingConfiguration="secure" />

    <endpoint address="" binding="webHttpBinding" contract="MyService.Interface" behaviorConfiguration="web" bindingConfiguration="basic" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="web">
      <webHttp defaultOutgoingResponseFormat="Json" faultExceptionEnabled="true" defaultBodyStyle="Bare" automaticFormatSelectionEnabled="false" />
    </behavior>
  </endpointBehaviors>
</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

I'm hosting a WCF service within ASP.NET. The WCF service requires a cookie for most operations. It works fine if ASP.NET session state is "InProc". However, we want to move the app to a web farm & I'd like to run the State Service on a dedicated machine. When I do this, the WCF methods do not generate the cookie.

Any ideas?

Code to add the cookie:

WebOperationContext.Current.OutgoingResponse.Headers[HttpResponseHeader.SetCookie] = "myCookie" + MyVal.ToString();

WCF configuration:

<system.serviceModel>

<bindings>
  <webHttpBinding>
    <binding name="secure">
      <security mode="Transport" />          
    </binding>
    <binding name="basic"></binding>                 
  </webHttpBinding>
</bindings>

<services>
  <service name="MyService" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="MyService.Interface" behaviorConfiguration="web" bindingConfiguration="secure" />

    <endpoint address="" binding="webHttpBinding" contract="MyService.Interface" behaviorConfiguration="web" bindingConfiguration="basic" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="web">
      <webHttp defaultOutgoingResponseFormat="Json" faultExceptionEnabled="true" defaultBodyStyle="Bare" automaticFormatSelectionEnabled="false" />
    </behavior>
  </endpointBehaviors>
</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文