繁体   English   中英

在WCF连接中更改ChannelFactory的IPEndpoint

[英]Changing IPEndpoint of ChannelFactory in WCF connection

是否可以使用ServicePoint将客户端的传出IP地址更改为WCF服务?

var localIpAddress = IPAddress.Parse("192.168.1.113");
ServicePoint servicePoint = ServicePointManager.FindServicePoint(new Uri(oDataSource.wcfURL));
servicePoint.BindIPEndPointDelegate =
                (sp, rm, retryCount) =>
                {
                    //Console.WriteLine(retryCount);
                    return new IPEndPoint(localIpAddress, 80);
                };

DuplexChannelFactory<IBSPubSubService> oChannelFactory = new DuplexChannelFactory<IBSPubSubService>(new InstanceContext(this), oBinding, oEndpoint);
oPubSubClient = oChannelFactory.CreateChannel();
oPubSubClient.Faulted += new EventHandler(WcfFaultedListener);
oPubSubClient.Opened += new EventHandler(WcfOpenListener);

我尝试使用上面的代码,但不起作用。 似乎一旦调用oChannelFactory.CreateChannel(),BindIPEndpointDelegate就会进入无限循环。

尝试绑定失败,直到int.MaxValue为止。

如果您无法选择本地端点,则只需返回null即可为您自动选择一个端点。

这是一个链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM