Web services question...
-
Hi, Can anyone tell me how a web service would get the calling computers IPAddress? I'm new to web services and I'm not sure where to look for this type of information. It's probably something really obvious that I'm unaware of. Thanks
Domain Name Services, or DNS. This is all handled by the TCP/IP stack on your machine. This is what resolves names like www.codeproject.com to IP addresses like 209.171.52.99.
Microsoft MVP, Visual C# My Articles
-
Domain Name Services, or DNS. This is all handled by the TCP/IP stack on your machine. This is what resolves names like www.codeproject.com to IP addresses like 209.171.52.99.
Microsoft MVP, Visual C# My Articles
-
Heath, I looked at the Dns class, but I didn't see anything obvious that would help me find out the calling computers ip address of my web service. Is their a way to do this? Thanks
You can use
Dns.GetHostByName
(or the asynchronousBeginGetHostByName
) to get the IP address, but you don't need to in most cases. When the proxy makes a request to the remote Web Services via its URL, the DNS client of your local machine will resolve the IP address, connect to the server, and make the request on the Web Service. This is all done internally - you do not need to resolve the IP address manually, just like you don't need to use the IP address in Internet Explorer and other Internet-ready applications.Microsoft MVP, Visual C# My Articles
-
You can use
Dns.GetHostByName
(or the asynchronousBeginGetHostByName
) to get the IP address, but you don't need to in most cases. When the proxy makes a request to the remote Web Services via its URL, the DNS client of your local machine will resolve the IP address, connect to the server, and make the request on the Web Service. This is all done internally - you do not need to resolve the IP address manually, just like you don't need to use the IP address in Internet Explorer and other Internet-ready applications.Microsoft MVP, Visual C# My Articles
-
So all I need to do is add this code to my web service and this will get the calling programs ip address?
string sHostName = Dns.GetHostName(); IPHostEntry ipEntry = Dns.GetHostByName( sHostName ); string sCallingAppName = ipEntry.HostName;
ThanksIf you want to log the IP address of the machine making the request to your web service, all you need to do us is get
Context.Request.UserHostAddress
inside a method call in your web service (Context
is a property inheritted from theWebService
from which your web service derives).Microsoft MVP, Visual C# My Articles
-
If you want to log the IP address of the machine making the request to your web service, all you need to do us is get
Context.Request.UserHostAddress
inside a method call in your web service (Context
is a property inheritted from theWebService
from which your web service derives).Microsoft MVP, Visual C# My Articles