Localhost webservice connection from android device - c#

I'm developing an android app and writing web services for that app on C#. So I need to try my webservices in my app from android device. I guess, for try my webservices from device, need to put my local IP address to instead of "localhost". And for use my local IP, i need to install IIS. I install IIS and put my IP to instead of localhost. I set binding settings from IIS manager.
IP:192.168.XX.XX
PORT:49244
I can access 192.168.XX.XX/49244 address, but when I try to access my webservices,192.168.1.36:49244/Service1.asmx, I get HTTP not found - detailed error.
What I need to do for access my services, where is my mistake?

Related

Connect device on LAN to ASP.NET Core Web API

I'm running VS2019 community, and I've created the default ASP.NET Core Web API project (ASP.NET Core 5.0), the one with the simple weather forecast example. And I am now trying to connect another computer to the URL. I run the example by using the [application name] in the run dropdown, and not IIS Express.
Both computers are connected via wifi to the same Router.
I do an ipconfig on the server machine to get it's IP (192.168.1.108)
And I have also enabled inbound connections from the ports 5000-5001 in the windows firewall setup
On the "client" machine I try to access the server with :
http://192.168.1.108:5000/swagger/index.html
or
https://192.168.1.108:5001/swagger/index.html
but neither seem to work? The page ends up timing out.
So on the machine running the server, I also completely disabled the windows firewalls (temporally, just to get things working).
But still get the same result?
Have I missed a step?
Maybe this will help you. Try to add IP of your host into Program.cs
var host = new WebHostBuilder().UseUrls("http://192.168.1.108:5000")

Can't find the device thats self hosting a web api

I'm using Owin and Topshelf to selfhost an ASP.net Web Api.
I am able to access it through localhost and 127.0.0.1 on the device that is self hosting it.
The idea is that any device that comes onto the network and has my computer or mobile application installed is able to communicate with that web api to request/update/remove data from the database hanging behind.
The issue i am having is that i have no way of finding out on what internal ip the service is actually running. I have no control/view over the network that it's installed onto (except through my code), this means i don't know what the ip or hostname might be, only the port number (on any other device that isn't hosting it).
I tried adding custom url's like shown below
StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:6969");
options.Urls.Add("http://127.0.0.1:6969");
options.Urls.Add(string.Format("http://{0}:6969", Environment.MachineName));
options.Urls.Add("http://+:6969");
Obviously localhost and 127.0.0.1 won't work for a remote device on the same network. The issue with the MachineName is that i don't have a say in the name of the machine either, meaning this could be anything. I assumued the wildcard would allow me to send a request on port 6969 and the host would catch it, this was sadly not the case.
This leaves me in a bit of an issue, i now have a self hosted Web api, on a machine with a random ip and name, and it needs to be accessed by other devices on the same network, The users are not able to manually enter ip, and i can't force a name onto the host computer. This all leaves me in a situation where im not sure wat else i could try, or if its even possible to reach the host computer without human interference.
Edit: I did come across something along the lines of a
network broadcast address
Which should in someway allow me to send out a message from a device, and let the server respond with its ip. Not sure how i would apply this to my self hosted web api though.
Basically, the idea is to have your web API application register its address to a service, such as DNS, which may be updating the IP address of a DNS A record. Then clients will query this service or DNS, to resolve the address to your application.

Connecting to a RESTful API from Xamarin.Forms mobile application (and other computers on the same network)

I am trying to connect my Xamarin.Forms mobile application to a RESTful API I'm hosting locally on my computer. I'm using Visual Studio for both the Xamarin.Forms mobile application and for the API, and for the API, I'm using ASP.NET Core (the specific template in Visual Studio is ASP.NET Core Web Application (.NET Framework) ).
It worked fine when I connected to it from my browser using a localhost address on the same computer I ran the API from (in my case, localhost:59475/api/ was the URL) and before connecting my mobile application to the API, I first tried to connect to the API from other computers on the same network, and I didn't manage to make it work so far. What I tried so far is the following - run the cmd command netsh http add urlacl url=http://*:59475/ user=everyone (along with other similar commands with other ports I thought may work), then I added an inbound firewall rule to allow all connections on that port. I then tried to connect to the API from other computers on the network by replacing "localhost" in the address with the IP of the computer running the API, and I received an HTTP 503 error when I did. Evantually what happend is when I tried to run the API from Visual Studio it showed an error of
Unable to connect to web server 'IIS Express'
"Undoing" the netsh http commands (netsh http delete urlacl...) made it work again as it did at first (again, only able to connect to it from the same computer using my browser). I don't know how to make it work and would like to receive help please! :)
Try the following:
add your external IP explicitly netsh http add urlacl url=http://192.168.0.6:60985/ user=everyone
In the root of the API solution folder open the '.vs/config/applicationhost.config' file (.vs is hidden by default)
in the bindings section add a new binding to the external address <binding protocol="http" bindingInformation="*:60985:192.168.0.6" />, mind to which site you are adding the bindings as there could be multiple.
Notes: example port 60985 yours could be different check the api
example IP: 192.168.0.6, change to your actual external IP address
You might want to disable the firewall for testing then when you confirm it works, enable it and add an exception rule
I had the same problem.
I solved with the magical Conveyor extension.
https://keyoti.com/products/conveyor/index.html?utm_source=conveyor&utm_medium=extension_moreinfo&utm_campaign=conveyor
Follow the guide on their website.
In netcore, disable SSL first (project property => debug)

Why is the uri for a self hosting application set as localhost?

I recently started looking into Asp.net Web Api self hosting. I'm following this article and I have two questions based on that.
Why is the URI for HttpSelfHostConfiguration pointing to localhost?
How would I give a website name like I would in IIS for the windows service? Because if I deploy this to a production server, how would the clients call the localhost?
Q. Why is the URI for HttpSelfHostConfiguration pointing to localhost?
A. localhost simply just means "this computer". It's typical to do it this way to make the intent clear. Nothing stops you from using an ip address.
Q. How would I give a website name like I would in IIS for the windows service? Because if I deploy this to a production server, how would the clients call the localhost?
A. You would change from HttpSelfHostConfiguration("http://localhost:80") to HttpSelfHostConfiguration("http://000.000.000:80") where 000.000.000 is the ip address of the host (the machine you are running the web application on)
Localhost is reserved loopback adres (ea 127.0.0.1) try ping localhost.
The origin is basic networking, it existed before .net
Pinging localhost was quite common to check if your own network card still worked. As it ping 127.0.0.1, is a ping to your own network card. Next step in conectivity issues was pinging your gateway and then some remote IP or so.
A client cannot connect to a remote localhost (it will point its own network card).
in regard to the article, a server listens to its own network card.
unless you have some multiple nic environment with specific routes to follow
but then there is a config file for that.
Localhost is the default allocation of Windows, if you want to change the default name binding,
answer is simple just go to
C:\Windows\System32\drivers\etc\ folder
you can find as hosts file there just open it in notepad, if you want to change the locally hosted name add a new line in that text file like
127.0.0.1 domain name you want to use
for example
127.0.0.1 techdoubts.net
then your localhost will be changed to techdoubts.net
and one more, add that new name in internet information services website binding also.

Hosting a C# Remoting Application

i have created an Chat Application in C# using TCPChannel and Remoting Service. My Application have 3 parts one is remoteobject, second is RemoteServer and third one is ClientSide. Everything is Working fine in my pc, mean if i run server application and client application in same server its works very good, because localhost. but when i try to host my server application in my VPS and client application in my pc then i can not connect with my server application. how can i specifies an Static IP to my Server Application so i can access my app from anywhere. please help
You may want to check out your firewall settings. You will need to open a port to allow outside traffic to access the particular port on your machine.
this constructor is using a fixed port: https://msdn.microsoft.com/en-us/library/cdb9dcxt(v=vs.110).aspx

Categories

Resources