开发者

can you use WCF connection to get your connecting IP address?

I have a Windows Service (.NET 3.5/C#) which is connecting to a WCF service on a external server on the public internet.

Can I use that WCF connection to get my computer's external IP address? The WCF service is hosted inside IIS on o开发者_高级运维ur application server. Can I do anything with that to get my external IP address?


Can I use that WCF connection to get my computer's external IP address?

If you want to get your external IP from within the service that sends a request than the answer is no. And it has nothing to do with WCF. Your computer may not even have an external IP because it may not be connected to internet directly. External IP may belong to the router that your computer is connected to. This external IP will be visible to the WCF service you connecting to. So this service can potentially let you know what external IP your request was coming from (if you add new 'MyIP' field in to the data contract).

Your machine   ->   Request                        ->   External WCF Service
Your machine   <-   Response(your IP is X.X.X.X)   <-   External WCF Service

Or you can scrap it from automation.whatismyip.com

Update based on your comment:

... and I want them to be able to get their own IP address and send it to the server.

They don't know their external IP addresses, but server will know so there is no need to send IPs.


if you are in .NET 3.5 or 4, in your WCF service use this code:

using System.ServiceModel;
using System.ServiceModel.Channels;

OperationContext context = OperationContext.Current;
MessageProperties prop = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpoint =
    prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address;

source: Obtaining client IP address in WCF 3.0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜