【发布时间】:2021-08-09 09:12:17
【问题描述】:
现在在客户端 app.config 中:
<system.serviceModel>
<client>
<endpoint name="FileEndPoint" address="net.p2p://ChangingName123/FileServer"
binding="netPeerTcpBinding" bindingConfiguration="PeerTcpConfig"
contract="FileClient.IFileService"></endpoint>
</client>
<bindings>
<netPeerTcpBinding>
<binding name="PeerTcpConfig" port="0">
<security mode="None"></security>
<resolver mode="Custom">
<custom address="net.tcp://191.14.3.11/FileServer" binding="netTcpBinding"
bindingConfiguration="TcpConfig"></custom>
</resolver>
</binding>
</netPeerTcpBinding>
<netTcpBinding>
<binding name="TcpConfig">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
在客户端代码中:
InstanceContext context = new InstanceContext(
new ChatClient(numberclient);
DuplexChannelFactory<IFileChannel> factory =
new DuplexChannelFactory<IFileChannel>(context, "FileEndPoint");
IFileChannel channel = factory.CreateChannel();
channel.Open();
我尝试这样做:
NetPeerTcpBinding binding = new NetPeerTcpBinding();
EndpointAddress endpoint = new EndpointAddress("net.p2p://ChangingName123/FileServer");
InstanceContext context = new InstanceContext(
new ChatClient(numberclient);
DuplexChannelFactory<IFileChannel> factory =
new DuplexChannelFactory<IFileChannel>(context, binding, endpoint);
但“PeerTcpConfig”有custom address="net.tcp://191.14.3.11/FileServer" 和bindingConfiguration="TcpConfig"
如何在代码中设置绑定自定义地址并为 NetPeerTcpBinding 绑定设置一个绑定 TcpConfig
【问题讨论】:
-
本文中的 app.config 中有多个端点,但需要示例如何在代码中生成以及在代码中询问您可以看到一个端点的多个绑定
-
先在ru讨论中发布这个问题,找到解决方案here