2013-07-12 18 views
1

我試圖在WCF服務中檢索登錄的Windows用戶。 我試過使用ServiceSecurityContext,但當前始終爲空。WCF中的ServiceSecurityContext.Current爲空

ServiceSecurityContext.Current.WindowsIdentity.Name 

我也試過使用OperationContext。在這種情況下,ServiceSecurityContext返回爲空。

OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name 

這裏是我的web.config:

<bindings> 
    <basicHttpBinding> 
    <binding name="HttpWindowsBinding"> 
     <security mode="TransportCredentialOnly"> 
     <transport clientCredentialType="Windows" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

<authentication mode="Windows"/> 

有人能看到我在做什麼錯?

更新: 我放棄了試圖讓ServiceSecurityContext工作。最後,我通過設置aspNetCompatibilityEnabled =「true」找到了解決方案。

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 

我還增加了以下屬性我的服務類:

[System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode = System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Required)] 

這讓我檢索與Windows用戶:

HttpContext.Current.User.Identity.Name 
+0

我希望您已將此綁定配置「HttpWindowsBinding」添加到您的服務中的端點。 – vibhu

+0

我有。還是行不通。 – ijason03

回答

-1

這是一個古老的職位,但去here ...

您需要設置TransportCredentialOnly

+0

歡迎來到SO,@zundapps_dot_com!當給出答案時,我們更喜歡答案能夠獨立地站在自己的位置,而不需要外部參考。 (這並不意味着你不應該在你的答案來自哪裏。) – Dan

相關問題