VB icon

Who is invoking my Web Service

Email
Submitted on: 1/1/2015 10:29:00 AM
By: Steven Henning (from psc cd)  
Level: Advanced
User Rating: By 4 Users
Compatibility: VB.NET
Views: 1476
 
     If you want to know who is invoking your Web service, you can obtain the IP Address from the Context.Request.UserHostAddress This will either return the invokers PC IP or the proxy they use. In the example code below I used this to restrict a function to only respond to calls from the PC the Web Service is running on, i.e. 127.0.0.1
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Who is invoking my Web Service
// Description:If you want to know who is invoking your Web service, you can obtain the IP Address from the Context.Request.UserHostAddress
This will either return the invokers PC IP or the proxy they use. 
In the example code below I used this to restrict a function to only respond to calls from the PC the Web Service is running on, i.e. 127.0.0.1
// By: Steven Henning (from psc cd)
//**************************************

<WebMethod()> Public Function YourIPAddress() As String
Dim sCallersIPAddress As String = Context.Request.UserHostAddress
Dim sReply As String
sReply = "<<- This is either your PC's IP, or the proxy you use."
Return (sCallersIPAddress & sReply)
End Function
<WebMethod()> Public Function LocalFunction(ByVal YourName As String) As String
Dim sCallersIPAddress As String = Context.Request.UserHostAddress
Dim sReply As String
If sCallersIPAddress <> "127.0.0.1" Then
' A webservice request from an external PC
sReply = "Hey, " & YourName & ", IP " & sCallersIPAddress & " may not execute this function!"
Else
' Do something different for calls from localhost
sReply = "Hello, " & YourName & ", IP " & sCallersIPAddress & " this app is runnning from " & Context.Request.PhysicalApplicationPath
End If
Return (sReply)
End Function


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.