Home How can I get the public IP and port my WCF service runs on?
Reply: 2

How can I get the public IP and port my WCF service runs on?

Attila Published in 2017-11-14 18:23:04Z

I'm fairly new to WCF. I want to send the client an URL, which points to a file on the server, so the client can download\view it.

So my idea is that I add the relative path to the IP the service is listening on.


The problem is, that every solution I found gives back localhost:someport/mysite Obviously, this is not really useful for the client.

Is there even a way to get the public IP from code on which the service is hosted?

Or should I just include the address in the config file, and change it whenever the IP changes?

EDIT: Thanks for the quick help guys, I will just include it in the config file then.

Brandon Miller
Brandon Miller Reply to 2017-11-14 18:34:35Z

Well, first of all, if you have no server application running (I.E Apache, etc), nothing will be able to connect to your endpoint. You may use a service like WAMP for this. Second, you need to forward whatever port you're using to be able to serve the file (this is done on your router config). No, there is no way to predict what the IP of the server it's connecting to is going to be ahead of time. This will have to be added to the client codebase manually. Finally, if this is going to be used in a production environment, I would STRONGLY recommend that you do not use something like WAMP, or a local environment at all, for something like this.

Shankar Reply to 2017-11-14 18:53:27Z

You need to call an external service, like whatismyip.com, and parse the response. There is no standard format for the response, hence not very reliable. Answered here: Get public/external IP address?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314099 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO