WCF中的ServicePoint无法绑定IP

时间:2017-09-05 00:33:52

标签: c# asp.net .net wcf networking

我有以下代码

 WSDualHttpBinding oBinding = new WSDualHttpBinding();
            oBinding.Security.Mode = WSDualHttpSecurityMode.None;
            oBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.None;
            oBinding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

            oBinding.ReceiveTimeout = new TimeSpan(0, 30, 0);
            oBinding.ReliableSession.Ordered = true;
            oBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 0, 7);

            EndpointAddress oEndpoint = new EndpointAddress(oDataSource.wcfURL);

            var localIpAddress = IPAddress.Parse("192.168.1.121");
            ServicePoint servicePoint = ServicePointManager.FindServicePoint(new Uri(oDataSource.wcfURL));
            servicePoint.BindIPEndPointDelegate =
                            (sp, rm, 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);

目标是使用特定的IP地址和端口连接到WCF服务。但是,当我尝试使用上面的代码时,似乎我无法再为wcf创建一个通道。删除服务点可以工作,但没有它我将无法选择我想要在多个NIC的情况下使用的单一IP。有人可以帮我吗?

0 个答案:

没有答案