如何提出请求之前,WCF HTTP客户端,以一个特定的出站ip地址绑定 [英] How to bind a WCF Http client to a specific outbound IPAddress before making the request

查看:196
本文介绍了如何提出请求之前,WCF HTTP客户端,以一个特定的出站ip地址绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的要求通过一个特定的IP地址出去。有没有办法做,在WCF。为什么我需要这个是一个小长篇大论,所以我宁愿不进入该解释。

I want my request to go out through a specific IP Addresses. Is there a way to do that in WCF. The explanation of why I need this is a little long winded so i'd rather not get into that.

下面是示例代码

string ipAddress = "192.168.0.32";
IService service;
ChannelFactory<IOmlService> factory = new ChannelFactory<IService>(new BasicHttpBinding(), new EndpointAddress("http://" + IPAddress + ":6996/IService"));
service = factory.CreateChannel();
service.Test();

下面是一个示例场景来解释正是我要找的。比方说,我有我的机器(192.168.0.30与192.168.0.31)上的两个IP地址。他们都可以打192.168.0.32。如果我现在运行这段代码,它会击中任何我的IPS(0.30或0.31)的IP(0.32)。我怎样才能迫使它要经过我的一个特定的IP(比如0.30)。有没有办法做到这一点使用WCF?

Here is an example scenario to explain exactly what i'm looking for. Let's say I have two IPs on my machine (192.168.0.30 and 192.168.0.31). Both of them can hit 192.168.0.32. If i run this code now, it will hit the IP (.32) from any of my IPs (.30 or .31). How can i force it to go through a specific IP of mine (say .30). Is there any way to do that using WCF?

推荐答案

该问题的答案是,它无法做到的。下面是微软的MVP答案

The answer to the question is that it cannot be done. Here is the answer from a Microsoft MVP

所以,你要让客户端机器主动选择网络之一adpater接口(安装就可以了)发送出去的WCF请求?这恐怕是出于WCF的控制,因为WCF只专注于以下地址:

So you want to let the client-side machine proactively select one of the network adpater interface(installed on it) to send out the WCF requests? I'm afraid this is out of WCF's control since WCF only focus on the following addresses:

**的行为时,作为东道主,我们可以选择绑定到特定主机名称/地址监听客户端请求
**当作为一个客户端,我们可以选择目的地地址/主机名发送请求。

** when behave as a host, we can choose to bind to a specific hostname/address to listen for client requests ** when behave as a client, we can choose the destination address/hostname to send request to.

这篇关于如何提出请求之前,WCF HTTP客户端,以一个特定的出站ip地址绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆