IIS Website Application doesnt work anything but port 80 - c#

I wrote a WCF service in visual studio 2017. I then added this service to IIS (not the express version but the full fledge IIS). It is added as an application under the default created website. I can access my service end-point without any issues at http://localhost/<websitename>/MyService.svc/test/123. /test/123 is just a simple GET endpoint.
The default website is already configured for port 80.
However, when I changed the port from 80 to say, 1234, it does not work. It merely returns me "Service Unavailable. HTTP Error 503." when I hit the /test/123 endpoint.
I have already executed the console command to add the port to ACL netsh http add urlacl url=http://+:1234/ user=everyone.
Does anyone know how can I get another port (non 80) to work?
Edit:
I am aware that there is an answer How to run WCF service on a specific port which explains how to bind to another port. However, the accepted answer uses the net.tcp protocol. I would like to use the HTTP protocol.
Is there any way to do it with HTTP protocol? If it cannot be done, then I guess ill have to redesign and swap over to net.tcp protocol.
I am extremely new to .NET development and WCF, so hopefully somebody with experience can point me in the right direction.

As it turns out, the problem had nothing to do with the so-called linked answer.
Prior to running my WCF service in IIS, I was trying to deploy it as a WAS and then Console application. In my process of getting those 2 implementations to work, I had to execute the command netsh http add urlacl url=http://+:1234/ user=everyone so that the port could be accessed.
By sheer luck, i stumbled upon this link:
https://serverfault.com/questions/666976/service-unavailable-if-i-try-to-access-iis-website-via-ip-address-works-fine-vi
Although it didnt have an accepted answer, the comments held the answer. My problem was caused exactly because I executed the netsh command. What happens is that the command causes that ip/port to be reserved, and thus, IIS cannot attach to the ip/port and therefore the Service Unavailable error. I assumed that if the WAS and Console version needed that command to be executed, then the IIS version needed it as well.
As for letting an IIS WCF Service be available on any other port, the process is super simple. Within IIS itself (Execute "inetmgr" in Run to launch), in the default or custom website you created, edit the binding and change the HTTP port to whatever port that you want. After that, its done. You should be able to access your application/website from that port via HTTP.
Eg:
http://localhost:<some port>/<websitename>/MyService.svc/test/123
My WCF Service config was a standard config that allowed for HTTP access.
If you would like to access it from another computer or from the internet, then you will need to configure your router to port forward your selected port (if needed) and ensure that your firewall allows data flow for that port.
Many "thanks" to the downvoters who assume this was some duplicate. Your "help" contributed in finding a solution to the problem.

Related

Why am I getting a 404 message from my C# webserver even after setting the appropriate URL ACL?

I have a web server built with HttpListener in C#. It is using a specific path on port 80 for GET requests being called from another C# application. It works between my development machine and a virtual machine. I set it up on another computer, and I start getting 404 responses from the server. I have the following command run to open the port and path:
netsh advfirewall firewall add rule name="Server HTTP" dir=in action=allow protocol=TCP localport=80
netsh http add urlacl url=http://+:80/svrpath/ user=%USERDOMAIN%%USERNAME% listen=yes
I cannot figure out why I keep getting 404 errors when I call a simple get to this server. If I run the server on my development machine, it works fine and the GET returns the expected json string. I have even turned off the the firewall on both sides and it continues to give me 404 errors. I have run the get command from a web browser with the same result.
I have also tried changing the user on the "add urlacl" command to values such as Everyone and Administrators to no avail.
Searching around Google has not given me any solution to this and I am looking for anyone who has any idea what could cause such a problem. All machines in question are running Windows 10 build 1709 and are connected on the local network. I'm sure there is something dumb I have missed somewhere, but I can't figure out what it is.
At this point all I can conclude is another process was locking the port so that my application was unable to respond to the requests. A restart and full re-installation of the program (including re-running all netsh commands) solved the problem and it has not recurred since doing that.

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)

When should I use ServiceFabricIntegrationOptions.UseUniqueServiceUrl

This seems to say that is is always necessary otherwise you may resolve an incorrect service -- as there is no guarantee that services won't move around etc...
The default asp.net core service template uses
UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
Is there a reason for this? When is it okay to not use the ServiceFabricIntegration middleware?
E: I see these are actually a flags enum. So likely you should always use UseUniqueServiceUrl https://github.com/Azure/service-fabric-aspnetcore/blob/develop/src/Microsoft.ServiceFabric.AspNetCore/WebHostBuilderServiceFabricExtension.cs
Respectfully, I don't think you have read the docs well enough. It is well explained here:
Services that use a dynamically-assigned port should make use of this middleware.
Services that use a fixed unique port do not have this problem in a cooperative environment. A fixed unique port is typically used for externally-facing services that need a well-known port for client applications to connect to. For example, most Internet-facing web applications will use port 80 or 443 for web browser connections. In this case, the unique identifier should not be enabled.
So summarized: when using Kestrel or WebListener you can choose to use a dynamic port or a fixed port. See the sections Use WebListener/Kestrel with a static port and Use WebListener/Kestrel with a dynamic port in the mentioned link. When you opt to use a dynamic port use ServiceFabricIntegrationOptions.UseUniqueServiceUrl, otherwise use ServiceFabricIntegrationOptions.None as the parameter for the middleware.
Now, as of the why you need this unique service url middleware in case of a dynamic port, there is a scenario that describes the possible problem:
If services use dynamically-assigned application ports, a service replica may coincidentally use the same IP:port endpoint of another service that was previously on the same physical or virtual machine. This can cause a client to mistakely connect to the wrong service. This can happen if the following sequence of events occur:
Service A listens on 10.0.0.1:30000 over HTTP.
Client resolves Service A and gets address 10.0.0.1:30000
Service A moves to a different node.
Service B is placed on 10.0.0.1 and coincidentally uses the same port 30000.
Client attempts to connect to service A with cached address 10.0.0.1:30000.
Client is now successfully connected to service B not realizing it is connected to the wrong service.
This can cause bugs at random times that can be difficult to diagnose

WCF http services blocked by windows 10 firewall

I have 3 self hosted WCF windows services communicating with each other over http port 80 using basic http binding. On the same machine I have a website (also running on default port 80) hosted in IIS which also manages and communicates with one of those services. Everything works fine within this windows 10 hosting machine i.e. the website can talk to the services and the services can talk to each other.
When I try to access the website from another PC on the network I get a message in the browser saying 'server DNS address could not be found'. I can't even access the WCF service metadata url.
This looks like a firewall issue on the host machine so I added inbound and outbound rules for TCP port 80 and made sure the rules 'World Wide Web Services (HTTP Traffic-In)' and 'World Wide Web Services (HTTPS Traffic-In)' are enabled. None of these changes worked so I removed the TCP rules I added.
Finally I disabled the firewall completely and I was able to access the website from another PC. However, when I re-enabled the firewall, the website continued to work and all of a sudden my WCF metadata is also accessible!
I don't understand why this is happening. I have successfully recreated the problem several times.
Can anyone offer an explanation or suggest any other firewall rules to try?
My end goal is to package up the services and website into an installer so I don't want my end users to have to mess around with the firewall. They may not even be able to turn it off and on again.
Many Thanks
How about outbound rules on port 80 for http?
Finally figured it out. The url I was using to access the hosting machine used the machines name. In order for the machine to respond to a name lookup was to enable the firewall rule called 'Network Discovery (NB-Name-In)' for the public profile. This rule allows traffic on UDP port 137. Once the name lookup has been cached the url will be properly routed. This explains why it worked after I disabled then enabled the firewall again.

Is it possible to redirect a url to another using a webproxy ( such as fiddler )

I'm trying to parse a WSDL file which is in another server but has hard codded "localhost" all over the document.
When I fetch it, obviously the program complains "connection refused" because nothing is running in my machine.
My question is: Is it possible to use a webproxy ( such as fiddler ) to redirect those localhost request to my other server so the WSDL references are complete?
:-/
Thanks
p.s. I could always have fixed the remote "wsdl" but the guy on charge will be here until next week and I would like to start working today.
You could use Fiddler as the proxy from your machine, and then have it rewrite the WSDL to change localhost to the correct machine name.
The FiddlerScript CookBook has an example on how to write this sort of script. Go to that page and search for "Remove all DIV tags (and content inside the DIV tag)". Just change the regex to match localhost and set the replace to the machine name you want to use.
If you have SSH access to the machine, you should be able to use SSH port forwarding to accomplish this. I'm assuming you're using Windows (based on the C# tag), so you can use Putty as explained here: Using port forwarding with PuTTY. Just follow those instructions to forward the desired port on "localhost" to the server that serves the WSDL.
Alternatively, if you're on a *nix based machine or a Mac, use SSH w/ the following command:
ssh -L PORTYOUWILLUSE:localhost:PORTONSERVER username#serverhostname
For example, if the WSDL were served on port 80, you could do
ssh -L 80:localhost:80 username#server
Once you're logged in (with either method), any requests to localhost on port 80 will be rerouted to the server.
If you only want to change it for a few minutes while you parse the WSDL, you might be able to change the HOST file and point "localhost" to the remote IP address. The hosts file is in "C:\Windows\System32\drivers\etc" in Windows VISTA/XP.
There's a few ways you could achieve this, none are particularly robust as long-term solutions, but you mention you just want something temporary until the dev gets back.
If everything after the domain matches (if your remote URL is otherwise the same as the localhost one), you can edit your localhost entry in your hosts file.
In system32\drivers\etc, copy the "hosts" file onto your desktop. Open in notepad and change this line:
127.0.0.1 localhost
Change the IP address (127.0.0.1) to your remote domain. Then copy the hosts file back into the etc directory. (Note: it's not possible to edit this file directly, as Administrator or otherwise).
If you have multiple domains on the remote web service, in IIS, you need to change the web site to serve for requests to "localhost", this might seem a bit odd, but it'll work because your machine will make requests to the server's IP address, but specify the request domain as "localhost". Right-click the website in IIS and select properties, then add the domain "localhost" to the list of HTTP-Header values supported by that web site. You can ignore all of this if your web site in IIS will serve content if you access it via an IP address. If that single IP address is shared between multiple web sites (which is usually the case), you'll get a "Bad hostname" error from IIS as it attempts to look up "localhost" and can't find which web site to direct the request to.
Another possibility is to use a personal proxy server called Proxomitron. It's a little old, and no longer under development, but it's very easy to setup and very solid.
Once you've installed it, open it and click "Config" - change the port it listens on to 80. Next you need to create a redirect rule (it's not actually a redirect, more of a rewrite of the url). You'll need to have a quick read of the docs to understand how to add your own redirect, but there's plenty of samples that ship with the app. The rule you're looking for is RDIR:
$RDIR( ) Is more sneaky and redirects the connection in Proxomitron without telling your browser. This is useful when you want your browser to think it going one place when, in reality, it's going somewhere else.

Categories

Resources