2009-06-10 40 views
1

當通過配置調用netTcp端點操作時,是否可以模擬客戶端身份?還有就是WCF配置客戶端內的部分,如下圖所示:在WCF中模擬客戶端標識w/netTcpBinding

<client> 
    <endpoint 
     address="net.tcp://localhost:8081/tcpExample" 
     binding="netTcpBinding" 
     bindingConfiguration="myTcpBinding" 
     contract="TestTcp.IHelloTcp" 
     name="NetTcpBinding_IHelloTcp"> 
     <identity> 
      <userPrincipalName value="[email protected]" /> 
     </identity> 
    </endpoint> 
</client> 

我的客戶不會失敗,好像連接到客戶端的身份是當前登錄的用戶,也就是我。

+0

您是否正在呼叫與託管您的wcf服務的服務器不同的服務器?如果是這樣,你可能會體驗到代表團的歡樂。 – Will 2009-06-10 19:13:49

回答

1

HMm ...不知道我關注。 netTcpBinding的默認行爲是使用Windows憑據 - 例如,您當前的Windows帳戶用於服務憑據。

這是開箱即用的默認設置。

如果你想模仿一些其他用戶,不,你不能在配置中做到這一點 - 你必須在代碼中這樣做。這是唯一的出路,對不起。

MyServiceClient client = new MyServiceClient(); 
client.ClientCredentials.Windows.ClientCredential.Domain = domain; 
client.ClientCredentials.Windows.ClientCredential.UserName = username; 
client.ClientCredentials.Windows.ClientCredential.Password = password; 

在配置中指定不同用戶的唯一方法是使用定義要使用的其他用戶帳戶的證書。您不能在配置文件中配置直接的Windows用戶帳戶及其密碼。

3

你真的有三種選擇:

  1. 手冊模擬 (WindowsIdentity.Impersonate)
  2. 聲明模擬 (OperationBehavior(模擬= Impersonation.Required))
  3. 完全模擬 (ServiceAuthorizationBehavior.ImpersonateCallerForAllOperations )

A另外,請確保您正在使用您的服務的帳戶(即[email protected])在機器和域級別都被授予適當的權限。