Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / May 2006

Tip: Looking for answers? Try searching our database.

Choosing source IP of webservice call

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
berto - 30 May 2006 15:13 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.