【问题标题】:How to programmatiacally set the Service Principal Name on a hosted service如何以编程方式在托管服务上设置服务主体名称
【发布时间】:2010-11-24 07:01:59
【问题描述】:

要使用配置文件执行上述操作,我会这样做:

<endpoint
  address="...."
  binding="netTcpBinding"
  bindingConfiguration="MyBinding"
  contract="IService1">
  <identity>
    <servicePrincipalName value="name"/>
  </identity>
</endpoint>

但是如何将它添加到下面的代码中呢?

Uri uri = new Uri("http://example.com/service");
ServiceHost host = new ServiceHost(typeof(Service1), uri);

NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
host.AddServiceEndpoint(typeof(IService1), binding, uri);
host.Open();

【问题讨论】:

    标签: c# .net wcf wcf-client wcf-configuration


    【解决方案1】:

    有点麻烦,需要使用AddServiceEndpoint方法的返回值并设置在那里:

    ServiceEndpoint serviceEndpoint = host.AddServiceEndpoint(typeof(IService1), binding, uri);
    EndpointAddress myEndpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity("YourIdentity"));
    serviceEndpoint.Address = myEndpointAddress;
    

    【讨论】:

      猜你喜欢
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 2014-09-28
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多