首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在 WCF 中跨域使用 kerberos 委派并传递 ClientCredentials

在 WCF 中跨域使用 Kerberos 委派并传递 ClientCredentials 的方法如下:

  1. 首先,需要在服务端和客户端的配置文件中启用 Kerberos 委派。

在服务端的配置文件中,添加以下代码:

代码语言:csharp
复制
<bindings>
  <wsHttpBinding>
   <binding name="KerberosBinding">
     <security mode="Transport">
       <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

在客户端的配置文件中,添加以下代码:

代码语言:csharp
复制
<bindings>
  <wsHttpBinding>
   <binding name="KerberosBinding">
     <security mode="Transport">
       <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
  1. 在服务端的配置文件中,添加以下代码以启用 Kerberos 委派: <authentication mode="Windows" /> <identity impersonate="true" /> </system.web>using System.ServiceModel; // 创建客户端通道 ChannelFactory<IService> factory = new ChannelFactory<IService>("KerberosBinding"); // 创建客户端代理 IService serviceProxy = factory.CreateChannel(); // 设置客户端凭据 ((ClientBase<IService>)serviceProxy).ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation; // 调用服务方法 serviceProxy.Method();using System.ServiceModel; // 获取客户端凭据 WindowsIdentity clientIdentity = ServiceSecurityContext.Current.WindowsIdentity; // 验证客户端凭据 if (clientIdentity.ImpersonationLevel == TokenImpersonationLevel.Delegation) { // 执行服务方法 }
  2. 在客户端的代码中,添加以下代码以传递 ClientCredentials:
  3. 在服务端的代码中,添加以下代码以接收 ClientCredentials:
  4. 最后,需要在服务端和客户端的配置文件中指定服务的地址和绑定。

在服务端的配置文件中,添加以下代码:

代码语言:csharp<services>
复制
 <service name="Service">
   <endpoint address="http://localhost:8000/Service" binding="wsHttpBinding" bindingConfiguration="KerberosBinding" contract="IService" />
  </service>
</services>

在客户端的配置文件中,添加以下代码:

代码语言:csharp<client>
复制
 <endpoint address="http://localhost:8000/Service" binding="wsHttpBinding" bindingConfiguration="KerberosBinding" contract="IService" name="KerberosBinding" />
</client>

以上就是在 WCF 中跨域使用 Kerberos 委派并传递 ClientCredentials 的方法。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

12分26秒

AJAX教程-01-全局刷新和局部刷新【动力节点】

10分57秒

AJAX教程-04-ajax概念

9分48秒

AJAX教程-06-创建异步对象的步骤第二部分

7分14秒

AJAX教程-08-全局刷新计算bmi创建页面

3分4秒

AJAX教程-10-全局刷新计算bmi创建servlet

9分25秒

AJAX教程-12-ajax计算bmi创建异步对象

9分12秒

AJAX教程-14-ajax计算bmi接收数据

6分33秒

AJAX教程-16-ajax第二个例子创建库和表数据

4分51秒

AJAX教程-18-ajax第二个例子创建页面

7分45秒

AJAX教程-20-ajax第二个例子创建servlet接收请求

22分1秒

AJAX教程-22-json介绍

4分31秒

AJAX教程-24-创建使用json的页面

领券