2011-03-28 61 views
0

我有以下配置一个WCF服务:WCF用户名clientCredentialType

 <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

我注意到,你的'service'元素的名称就是'Service1'但合同的名称是'TestWcfService.IService1'。 'Service1'是否定义在同一个命名空间中?如果是这样,你必须使用全名。您目前的配置可能根本没有使用。 – 2011-03-28 08:48:15

回答

相关问题