Reputation: 157
I'm using a web service and connect it using httpWebRequest.create api. If i change the TCP port number In IIS other than 80 then my application could not connect to it. How can i set port number in System.Url object as set in IIS so that my application can connect to web service.
Upvotes: 2
Views: 21801
Reputation: 3102
Determining the port of an IIS that runs on a remote machine is not easy. Either you will need to have a different way of communicating the configuration (like a service), or use a portscanner that will check all possible ports (not recommended).
but, if the IIS is running on the local machine, you can use the appcmd
command to get a list of sites running in IIS.
appcmd list site
If you want to do this programmatically in C#, you could do something along the lines of:
// Setup ProcessStartInfo
var processInfo = new ProcessStartInfo();
processInfo.FileName = Environment.ExpandEnvironmentVariables("%windir%\system32\inetsrv\appcmd.exe");
processInfo.Arguments = "list site";
processInfo.RedirectStandardOutput = true;
processInfo.UseShellExecute = false;
// Start the process
var process = new Process();
process.StartInfo = processInfo;
process.Start(processInfo);
// Capture the output and wait for exit
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
// Parse the output
var ports = Regex.Matches(output, ":([0-9]+):");
foreach (Match port in ports)
{
// TODO: Do something with the ports here
Console.WriteLine(port.Groups[1].Captures[0].Value);
}
Upvotes: 0
Reputation: 49970
Using WebRequest.Create
with string parameter :
WebRequest.Create("http://{server}:{port});
Using WebRequest.Create
with uri parameter :
Uri myUri = new Uri("http://{server}:{port}");
WebRequest.Create(Uri);
Upvotes: 0
Reputation: 88
I think, if the Uri of your webservice is http://webservice/ then you might just do http://webservice:1234 where 1234 is your new port..
Upvotes: 0
Reputation: 60065
use URI in form http://example.com:8080/
where 8080 can be any other
Upvotes: 4
Reputation: 72860
You'd normally do this by appending the port like so:
http://www.example.com:81/path/to/page
Upvotes: 4