Wcf服务中的Cookies OperationContract

时间:2010-09-15 18:16:28

标签: c# wcf cookies operationcontract

是否可以在wcf服务的OperationContract中读取cookie?我试图在合同方法中读取cookie值,但它总是空的。如果我从.aspx页面读取相同的cookie,则该值存在。有什么想法吗?

2 个答案:

答案 0 :(得分:1)

你是如何托管他们的? WCF旨在与主机无关 - 即,在IIS之外托管时,您的服务仍然可以正常工作。但是,有一种兼容模式可能对您有所帮助:

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

默认值为false并禁用大多数ASP.NET功能,如HttpContext.Current。

答案 1 :(得分:1)

BasicHttpBinding.AllowCookies Property可能会解决这个问题,正如EnricoManaging shared cookies in WCF上发表的博文(引用here)所述。该帖子包含web.config片段:

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

但没有使用它的代码片段(博客文章中包含使用相同Cookie和不同Web服务的更复杂解决方案的代码)。

========编辑==========

或者甚至是allowCookies=false

相关问题