tags:

views:

220

answers:

3

I need to access simultaniously multiple instances of a web services with the following Url. The web services is hosted in IIS and has SSL enabled.

https://services.mysite.com/data/data.asmx

Usually, when we do this process manually, we go one by one and update the Windows host file (c:\Windows\System32\drivers\etc\hosts) like this :

192.1.1.100 services.mysite.com

I would like to automate the process and do it with some multithreading. So I cannot change the Host file. Is there a way to simulate a host file when we do a HTTP request in C#?

Thanks!

A: 

I think you get the same effect by setting the proxy server of that specific request to the IP address of the actual Web server you want to send the request to.

Mehrdad Afshari
A: 

You can change the URL that your request is hitting at runtime, something like this:

svc.Url = "http://firstServer.com";

So if you create a program that loops through each of your desired servers, just update the URL property directly (that example is taken from WSE 3 based web services).

Eric J.
I cannot do that... Otherwise SSL will fail.
Martin
Why would SSL fail?
Eric J.
Because SSL looks for the domain, no?
Martin
LOL, I see. You have the same domain each time mapping to a different IP. You COULD write some code that edits the hosts file each time, but be very careful about how you grant permissions to your hosts file if you do that (if someone can hack your hosts file, they can do all kinds of bad things to you). Alternatively, you might consider setting up an HTTP proxy server. Instead of allowing access to hosts (bad) you could programmaticly change the configuration of the proxy server (not so bad). I have used Apache in a similar way (http://httpd.apache.org/docs/2.2/mod/mod_proxy.html)
Eric J.
A: 

If you know the IP address of the server's SSL endpoint (which isn't necessarily the same as the server's default IP address), then you could just aim you web-service at that? Obviously the SSL check will fail, but you can disable that through code...

ServicePointManager.ServerCertificateValidationCallback += delegate
{
    return true; // you might want to check some of the certificate detials...
};
Marc Gravell
I am getting "The request failed with HTTP status 403: Forbidden.".ServicePointManager.ServerCertificateValidationCallback += delegate{ return true; };dataUrl = "http://machine1/dataaccess/DataService.asmx";DataService dataService = new DataService(dataUrl);return dataService.GetData();The problem is that without the Host file, I am unable to use this Url : https://services.mysite.com/data/data.asmx. How do I hit a specific machine and bypass SSL?
Martin