簡體   English   中英

使用自托管的WCF WebServiceHost進行模擬將獲得“發生操作錯誤”。 錯誤

[英]Impersonation using a self-hosted WCF WebServiceHost gets 'An operations error occurred.' error

所以我一直在為此打頭。 我有一個自托管的WCF服務:

var webServiceHost = new WebServiceHost(helloWorld);
webServiceHost.Authorization.ImpersonateCallerForAllOperations = true;

var uri = new Uri(BaseUri + webService.UriDirectory);
var webHttpBinding = new WebHttpBinding(webHttpSecurityMode);
webHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

var sep = webServiceHost.AddServiceEndpoint(IHelloWorld, webHttpBinding, uri);
var webHttpBehavior = new WebHttpBehavior {HelpEnabled = true};
sep.Behaviors.Add(webHttpBehavior);

webServiceHost.Open();

我已經將以下屬性應用於我的方法:

[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public List<GpoItem> GetAll()
{
    using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
    {
        // Execute GPO code here...
        return new List<GpoItem>();
    }
}

要添加更多上下文,我基本上有一個Web服務,該服務允許一個人登錄到網頁,在域上創建GPO。 在控制台中運行此程序效果很好,因為我以登錄的域用戶身份運行它。 作為Windows服務運行它會引發“訪問被拒絕”異常。 因此需要模仿。 我在上面輸入了以下更改的代碼,然后得到“發生操作錯誤。 (來自HRESULT的異常:0x80072020)。 仍在谷歌搜索中向我顯示其權限問題。 我以管理員身份登錄到Web服務測試環境,因此我具有完全訪問權限,並且顯示出可以像管理員一樣在控制台中運行它。 我覺得我缺少在某些地方設置一些標志。

有任何想法嗎?

[Update1]我嘗試將服務從作為本地系統運行切換為網絡服務,但是仍然遇到相同的問題。

[Update2]當我登錄到承載WCF服務的服務器(作為本地系統運行)並直接在該計算機上使用瀏覽器時,一切正常。 委派用戶身份驗證似乎是一個問題……在這里仍然未知。

顯然,一個人只能從WCF屬性中獲得一個模擬級別的令牌,該令牌只能用於本地資源訪問。 相反,我不得不使用LogonUser API,以便獲得具有網絡資源訪問權限的Delegate級令牌。 [1]

[1] http://msdn.microsoft.com/en-us/library/ff649252.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM