This is a complex issue that WCF doesn't seem to be serving very well.
The only component in the .NET platform that appears to be directly concerned with the client address problem is ServicePoint . In particular, it has a BindIPEndPointDelegate property that allows you to control how it selects the client IP address. The documentation for this property includes the following:
Some load balancing methods require the client to use the specific local IP address and port number, not IPAddress.Any (or IPAddress.IPv6Any for Internet Protocol Version 6) and the ephemeral port. Your BindIPEndPointDelegate can satisfy this requirement.
Therefore, you should be able to change the service point associated with your URL as follows:
var servicePoint = ServicePointManager.FindServicePoint( new Uri("http://contoso.com/service.svc")); servicePoint.BindIPEndPointDelegate = (sp, remote, retryCount) => new IPEndPoint(address, portNumber);
Obviously, this type of code requires your classes to learn about the protocol and end address the client will interact with. Most likely, it would be most appropriate to configure this logic as client behavior that can be applied to your client channel.
source share