如何以编程方式在托管服务上设置服务主体名称
要使用配置文件执行上述操作,我会这样做:
<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();
To do the above using the config file I would do:
<endpoint
address="...."
binding="netTcpBinding"
bindingConfiguration="MyBinding"
contract="IService1">
<identity>
<servicePrincipalName value="name"/>
</identity>
</endpoint>
But how do I add it to the below code?
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点麻烦,需要使用AddServiceEndpoint方法的返回值并在那里设置:
It's a bit cumbersome, you need to use the return value of the AddServiceEndpoint method and set it there: