gpt4 book ai didi

c# - 如何使用具有相同契约(Contract)和绑定(bind)的动态端点创建多个 wcf 服务实例而不保存在 app.config 中?

转载 作者:行者123 更新时间:2023-11-30 17:05:54 26 4
gpt4 key购买 nike

这是我的服务器端app.config:

<services>
<service name="PokerService.PlayerService" behaviorConfiguration="ServiceBehaviorPlayer">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5054" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="player" binding="netTcpBinding" bindingConfiguration="PlayerBinding" contract="PokerService.IPlayerService" />
<endpoint address="player/mex" binding="mexTcpBinding" name="ServiceBehaviorPlayer" contract="IMetadataExchange" />
</service>
</services>

我在客户端代码中生成动态端点:​​

ServiceHost host = new ServiceHost(typeof(PokerService.PlayerService));

NetTcpBinding binding = new NetTcpBinding(SecurityMode.Message);
binding.Name = "NetTcpBinding_IPlayerService";
binding.Security.Message.ClientCredentialType = MessageCredentialType.IssuedToken;

ServiceEndpoint ep = host.AddServiceEndpoint(
typeof(PokerService.IPlayerService),
binding,
"net.tcp://localhost:5054");
EndpointAddress myEndpointAdd = new EndpointAddress(new Uri("net.tcp://localhost:5054/player1"),
EndpointIdentity.CreateDnsIdentity("pident.cloudapp.net"));
ep.Address = myEndpointAdd;

对于服务测试代码:

var PlayerChannelFactory = new DuplexChannelFactory<ClientApplication.PlayerService.IPlayerService>(new PlayerHandler(handler, this), binding, ep.Address);

PlayerChannelFactory.Credentials.SupportInteractive = false;
PlayerChannelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
PlayerServiceProxy = PlayerChannelFactory.CreateChannelWithIssuedToken(User.Instance.userToken);

现在我收到这个错误

Error

有什么想法吗?

最佳答案

客户端配置文件如下所示:

<client>
<endpoint address="net.tcp://localhost:5054/player" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IPlayerService" contract="PlayerService.IPlayerService" name="NetTcpBinding_IPlayerService">
<identity>
<dns value="pident.cloudapp.net"/>
</identity>
</endpoint>
</client>

关于c# - 如何使用具有相同契约(Contract)和绑定(bind)的动态端点创建多个 wcf 服务实例而不保存在 app.config 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16014572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com