首页
学习
活动
专区
工具
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 的方法。

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

相关·内容

领券