我有以下启动 WCF P2P 服务的代码:
private static readonly EndpointAddress EndpointAddress =
new EndpointAddress("net.p2p://eigenein.Test.Wcf");
...
public void Start()
{
NetPeerTcpBinding binding = new NetPeerTcpBinding();
binding.Security.Mode = SecurityMode.None;
ServiceEndpoint endpoint = new ServiceEndpoint(
ContractDescription.GetContract(typeof(IChat)),
binding,
EndpointAddress);
endpoint.Behaviors.Add(new ProtoEndpointBehavior());
host = new Chat();
channelFactory = new DuplexChannelFactory<IChatChannel>(
new InstanceContext(host), endpoint);
channel = channelFactory.CreateChannel();
channel.Open();
}
据我了解,WCF 会自动确定侦听端口和连接到其他对等方的端口。但是我可以为每个对等体设置两个特定的不同端口:监听的端口和连接到另一个对等体的特定端口吗?就像是:
private static readonly EndpointAddress SourceEndpointAddress =
new EndpointAddress("net.p2p://eigenein.Test.Wcf:808");
private static readonly EndpointAddress TargetEndpointAddress =
new EndpointAddress("net.p2p://eigenein.Test.Wcf:909");
我想要实现的目标:允许对等方通过静态 NAT 端口映射进行连接。我无法更改这些映射。