WebSecurity可以在WCF服务中工作吗?

Dab*_*uto 5 asp.net-mvc wcf webmatrix

我是SimpleMembership模型的新手.WebSecurity在Web页面中运行良好,但是当我在服务中使用它时遇到问题.

我有一些网络服务,在以下工作:

<binding name="SecureBasicBindingWithMembershipConfig">
      <security mode="TransportWithMessageCredential">
           <transport clientCredentialType="None" />
           <message clientCredentialType="UserName" />
      </security>
</binding>
Run Code Online (Sandbox Code Playgroud)

我尝试从Web服务恢复用户ID.

如果我使用WebSecurity.IsAuthenticated,它会返回IsAuthenticated = 'WebMatrix.WebData.WebSecurity.IsAuthenticated' threw an exception of type 'System.ArgumentNullException'

但是,System.Web.Security.Membership.GetUser()正确返回使用 用户标识.

WebSecurity可以在WCF服务中使用,还是我做错了什么?