我有一个WCF服务,其配置如下:
<service behaviorConfiguration="MyServiceBehavior" name="Service1">
<endpoint address=""
binding="wsHttpBinding" bindingConfiguration="MembershipBinding"
name="ASPmemberUserName" contract="TestWcfService.IService1" />
</service>
.
.
.
.
.
<wsHttpBinding>
<binding name="MembershipBinding">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
我想将用户名传递给客户端上的服务代理并在服务器端检索它。我使用下面的代码将用户名传递给代理类:
Service1Client sc = new Service1Client();
sc.ClientCredentials.UserName.UserName = HttpContext.Current.User.Identity.Name;
当我尝试在服务器上检索用户名时,ServiceSecurityContext.Current
返回null。任何想法为什么会这样?
答案 0 :(得分:3)
问题是由证书设置引起的。以下链接有助于解决问题:
A simple WCF service with username password authentication: the things they don’t tell you