要使用配置文件执行上述操作,我会这样做:
<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();