簡體   English   中英

從其他WCF服務調用WCF服務時傳遞Windows憑據

[英]Pass windows credentials when invoke wcf service from other wcf service

我有以下問題:

我有兩個WCF服務都使用basicHttpBinging定義為:

    <binding name="DefaultBasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00"
      receiveTimeout="01:00:00" sendTimeout="01:00:00" maxReceivedMessageSize="2147483647">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
      </security>
    </binding>

在web.config中,我也有以下幾行:

< authentication mode="Windows"/>
< serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

然后,我有調用ServiceNo1的silverlight應用程序。 在服務器端,執行服務方法。 在她的身體中,ServiceNo1和ServiceNo2作為客戶端被調用。

ServiceNo1 client1 = new ServiceNo1();
client1.ExecuteNextMethod1();


ServiceNo2 client2 = new ServiceNo2();
client2.ExecuteNextMethod2();    

這在locahost上完美運行。 當它在dev上發布時-問題開始了。

在Silverlight應用程序調用的方法中執行服務方法時,將引發異常:

Exception type: 
System.ServiceModel.Security.MessageSecurityException  

Message: 
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. 
The authentication header received from the server was 'Negotiate,NTLM'. 

看來Windows憑據未通過。

上面列出的設置也在開發人員中。 兩個服務器(localhost和dev)都在IIS上設置了“僅Windows身份驗證”。

有人不能幫我嗎?

最有可能發生的是在本地主機上,您的Web服務器正在您的憑據下運行。 在開發服務器上,Web服務器將在其他服務帳戶下運行(例如,您的應用程序的IIS應用程序池服務)。

最好的解決方案是獲取針對第二項服務授權運行的服務帳戶。

還有其他選擇-將您的用戶憑據用作開發人員中的服務帳戶(我假設這不是受控環境中的選項),或者在服務器端模擬您的憑據(再次-這在受控環境中不太可能適用)環境)。

編輯對您來說最好的選擇可能是模擬用戶的憑據。 有關實現,請參見此MSDN文章 我對Silverlight不太熟悉,但是您應該可以執行以下操作:

using System.Security.Principal;

------------------------

WindowsImpersonationContext impersonationContext;
impersonationContext = 
    ((.WindowsIdentity)HttpContext.User.Identity).Impersonate();

//Call your service here.

impersonationContext.Undo();

請注意,您可能會遇到Double-Hop問題,Windows不允許您將用戶憑據從一台服務器傳遞到另一台服務器-我將閱讀鏈接文章作為背景。

暫無
暫無

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

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