WCF 身份验证服务代理 - CookieContainer 不可用

标签 wcf authentication wcf-security

我已按照 msdn 的建议启用了 ASP.Net 身份验证服务。然后,我尝试通过控制台应用程序或 winforms 应用程序使用该服务(通过向本地 WCF 服务添加服务引用)。我正在执行自定义身份验证和传输安全性(因此我正在处理 Global.asax 中的 AuthenticationService.Authenticating 事件,该事件工作正常)。

身份验证本身工作正常,但通过添加服务引用创建的代理不包含 CookieContainer 属性。当我尝试将 cookie token 传递给需要身份验证的后续服务时,这显然是一个问题。

此外,在下面的客户端代码中,IsLoggedIn() 返回 false,我猜测这与不存在 cookie 容器有关。

ServiceReference1.AuthenticationServiceClient client = 
                  new ServiceReference1.AuthenticationServiceClient();
bool isLoggedIn = client.Login("test", "test", "", true); //returns TRUE
bool check = client.IsLoggedIn(); //returns FALSE

这是我的服务 web.config:

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <system.web.extensions>
    <scripting>
      <webServices>
        <authenticationService enabled="true"
           requireSSL = "false"/>
      </webServices>
    </scripting>
  </system.web.extensions>
  <system.serviceModel>
    <services>
      <service name="System.Web.ApplicationServices.AuthenticationService"
          behaviorConfiguration="AuthenticationServiceTypeBehaviors">
        <endpoint contract="System.Web.ApplicationServices.AuthenticationService"
          binding="basicHttpBinding"
          bindingConfiguration="userHttps"
          bindingNamespace="http://asp.net/ApplicationServices/v200"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="userHttps" allowCookies="true">
          <!--<security mode="Transport" />-->
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="AuthenticationServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  </system.serviceModel>
</configuration>

编辑:我应该添加其他内容,我调用 Login 方法执行了服务的 Fiddler session ,并且正在设置 cookie 并将其发送回客户端。但是没有 CookieContainer 我该怎么办?

最佳答案

When this option is enabled the client will make sure all cookies received from a given web service are stored and properly sent on each subsequent request in a transparent fashion. But there is a catch: the cookie is only handled in the conversation with one web service. What if you need to send the same cookies to different web services?

如果您需要将相同的 cookie 发送到多个服务,请阅读本文:http://megakemp.wordpress.com/2009/02/06/managing-shared-cookies-in-wcf/

关于WCF 身份验证服务代理 - CookieContainer 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11402970/

相关文章:

javascript - 从 Jquery 或 JavaScript 调用时的 WCF 身份验证方法?

asp.net - 如果只有一个 UI 应用程序会使用它,那么创建 WCF 服务层有什么好处吗?

.net - 找不到配置绑定(bind)扩展

php - 存储 session 以供成员(member)区使用

ios - 如何识别应用程序的用户?

Spring Security 执行顺序

wcf - 如何使用 WCF 签署 X509 token

c# - 第一次执行时找不到 WCF 端点,第二次执行时找到

c# - 使用 WCF 服务拒绝连接

java - 策略异常 : None of the policy alternatives can be satisfied in WCF Service Call