invoking a web service from another machine - c#

this is my question:
i need to invoke a web service hosted on HostA from a web browser on HostB.
i create a web service on HostA, i started it with F5 and this is the local url:
http://localhost:55432/Service1.svc
On HostB, i used the same url changing localhost with the HostA IP (pingable).
But it doesn't work. The Page return a "Unable To Connect to IP-Address".
i don't think it's a code problem, but it look like a connection/security problem.
Thanks for helps.

By default, the Visual Studio web servers (Cassini for older implementations, IIS express for newer implementations) do not even bind to your network adapter's IP address, instead only binding to localhost. So, by default, they do not accept remote connections.
If you're using Cassini, you can refer to how to access cassini server remotely in LAN for demo? for more information.
IIS express is handled differently, as evidenced in IIS Express enable external request.

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")

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)

403 Error For Web Service Call

I am using a 3rd-party tool that runs as a Microsoft Service on a Windows Server 2008 R2 machine. The machine is using a Dell SonicWall firewall. The tool has defined ports that it is listening on of which I have opened one. Using an external web tool that port is listed as open. The service has been installed and shows as running when I run services.msc.
Everything runs great on my local machine. However, when I try to query the service I get a 403 error. The following is what the query URL looks like:
https://{siteUrl}:{portNumber}/scanservice/v2/getstatus?method=jQuery111106758983342442662_1428439579840&_=1428439579841
This is an AJAX GET request coming from an ASP.NET MVC application.
The code attempts to find an open port by querying 3 ports that are the https ports for the service. The first two are ports that I have not opened on the machine. These queries time out which is what I would expect. The last port is the one I have opened on the server. I immediately get a 403 error.
Is there somewhere where I need to expressly allow that service, not just the port?
It is a case where your public IP is not whitelisted on the web service hosting server

Consuming Asp.net web service from remote computer

I create Asp.net WS and host it on the IIS.Now i want to consume it from remote computer or another computer.When i insert the URL of the WS on the remote computer an error message appears inside internet explorer browser page says
This program cannot display the web page
i work on Visual studio 2008, windows 7 and the client application is Asp.net website.
i don't know what is the problem??
have i connect the two computers with LAN(make network between them) or just enough each one connect to the internet??
Your computers need to be able to connect to each other.
If they on LAN, then You need to specify LAN address for asp.net WS.
Also check Your firewall for blocking connections, need to be sure that port were IIS hosted is available for connection
If nothing helps, then provide us more information about problem.
Really i don't know what is the problem.When i do the same thing in another computer it runs but on my laptop doesn't run.

How can I configure Cassini web server to accept requests to different hosts?

See duplicate: Customizing the cassini webserver
I have a web service hosted using Cassini web server. It works fine if I reference it by localhost, but when I use my machine's name (even using the browser locally), I get:
Server Error in '/' Application.
HTTP Error 403 - Forbidden.
Version Information: Cassini Web Server 1.0.40305.0
How can I configure it to accept all requests?
Cassini is specifically build to reject any outside connections. You could rebuild from sourcecode if you want it to accept outside connections.
Edit:
In reply to the below comment on what to edit in the sourcecode, you'd probably want to change the following in Server.cs on line 88:
_socket = CreateSocketBindAndListen(AddressFamily.InterNetwork,
IPAddress.Loopback, _port);
Into something like this:
_socket = CreateSocketBindAndListen(AddressFamily.InterNetwork,
IPAddress.Any, _port);
This will bind the listening socket to all available IP addresses on the system instead of only to the localhost address (127.0.0.1).
To update this answer, IIS Express is a new alternative that allows this.
http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx
To avoid anyone else having to go further, if you need a lightweight web server for production use, IIS-Express is not recommended (by themselves) for that purpose .

Categories

Resources