Hi all,
I've been searching around for a long time to solve a question I have,
and haven't found a solution yet, hope some of you can help me.
The problem is that I have a server which has two IP addresses, and a
web application which consumes webservices from other servers. The
thing is that, in my app., I want to be able to select which IP
address, from the two possible, is used as source IP whenever I make a
call to a webservice. Is it possible?
For more information, the server is running Windows Server 2003 and the
web application is written in C#.
I hope I explained the question fine.
Thanks in advance,
Albert
Gaurav Vaish (www.EduJini.IN) - 30 May 2006 17:56 GMT
> thing is that, in my app., I want to be able to select which IP
> address, from the two possible, is used as source IP whenever I make a
> call to a webservice. Is it possible?
Just before invoking the web-method from the client, set the Url property to
whatever you want.

Signature
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://webservices.edujini.in
-------------------
berto - 31 May 2006 11:49 GMT
Thanks for the response Gaurav, but I think I didn't explain well. I
don't need to choose the url/ip of the web-method I am calling, I need
to choose from which of my local machine ips does the call come out.
Thanks again
Albert
Kirk Allen Evans - 31 May 2006 13:55 GMT
using System;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "urn:learnwebservices.net:samples")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService
{
[WebMethod]
public string EchoMyIPAddress()
{
return HttpContext.Current.Request.UserHostAddress.ToString();
}
}

Signature
Kirk Allen Evans
Developer Evangelist
Microsoft Corporation
blogs.msdn.com/kaevans
=== This post provided "AS-IS" with no warranties and confers no rights ===
> Thanks for the response Gaurav, but I think I didn't explain well. I
> don't need to choose the url/ip of the web-method I am calling, I need
> to choose from which of my local machine ips does the call come out.
>
> Thanks again
> Albert
Gaurav Vaish (www.EduJini.IN) - 31 May 2006 19:19 GMT
> return HttpContext.Current.Request.UserHostAddress.ToString();
Oops!
Solution already provided...
btw, you don't need to do a ToString(), the property is itself a string. :-)

Signature
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://webservices.edujini.in
-------------------
Gaurav Vaish (www.EduJini.IN) - 31 May 2006 19:19 GMT
System.Web.HttpRequest:
1. UserHostAddress (contains the IP)
2. UserHostName (contains the hostname if resolved, or IP if unresolved)
HttpRequest can be had directly from:
System.Web.HttpContext.Current.Request
HTH

Signature
Happy Hacking,
Gaurav Vaish
http://www.mastergaurav.org
http://webservices.edujini.in
-------------------
> Thanks for the response Gaurav, but I think I didn't explain well. I
> don't need to choose the url/ip of the web-method I am calling, I need
> to choose from which of my local machine ips does the call come out.
>
> Thanks again
> Albert