简体   繁体   English

WCF服务OperationContract中的Cookie

[英]Cookies in wcf service OperationContract

Is it possible to read cookies in the OperationContract of a wcf service? 是否可以在wcf服务的OperationContract中读取cookie? I am trying to read a cookie value in the contract method, but its always empty. 我正在尝试在contract方法中读取cookie值,但它始终为空。 If I read the same cookie from a .aspx page, the value is present. 如果我从.aspx页读取相同的cookie,则该值存在。 Any ideas? 有任何想法吗?

How are you hosting them? 您如何托管他们? WCF is intended to be host-neutral -- ie your services should still work when hosted outside of IIS. WCF旨在与主机无关(例如,在IIS外部托管时,您的服务仍然可以工作)。 However, there is a compatibilty mode which might help you: 但是,有一种兼容模式可以帮助您:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>

The default value is false and disables most ASP.NET features like HttpContext.Current. 默认值为false,并禁用大多数ASP.NET功能(如HttpContext.Current)。

The BasicHttpBinding.AllowCookies Property may fix this, as mentioned at the start of Enrico 's blog post on Managing shared cookies in WCF (referenced here ). BasicHttpBinding.AllowCookies属性可以解决这个问题,如在开始提到的恩里克的博客帖子上的WCF管理共享饼干 (参考这里 )。 The post includes the web.config fragment: 该帖子包括web.config片段:

<system.ServiceModel>
    <bindings>
        <basicHttpBinding allowCookies="true">
    </bindings>
    <client>
        <endpoint address="http://localhost/myservice"
                  binding="basicHttpBinding"
                  contract="IMyService" />
    </client>
</system.ServiceModel>

but no code fragment using it (the blog post has code for more complex solutions using the same cookies with different web services). 但没有使用它的代码片段(博客文章中包含使用相同Cookie和不同Web服务的更复杂解决方案的代码)。

======== EDIT ========== ========编辑==========

Or perhaps even allowCookies=false 甚至甚至allowCookies = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM