2011-03-28 60 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

回答

相關問題