Accessing Host Header within Web Services Method

I have a web service that I need to retreive the host header used to access the service.  In classic ASP, I would use Request.ServerVariables("SERVER_NAME"), but I am having a hard time doing this from within VB.NET.  In the web services "code-behind" (myservice.asmx.vb) page, I don't have access to the Request object, and if I try to use System.Web.HttpRequest object, it doesn't provide for any properties like ServerVariables, it only provides Equals and ReferenceEquals in the IntelliSense dropdowns.  I just need to be able to determine the difference if the web service is being accessed via:
     http://test1.mysite.com/myservice.asmx/mymethod
as opposed to:
     http://test2.mysite.com/myservice.asmx/mymethod

Any help is appreciated!
bmcclearyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CJ_SCommented:
Try using the current httpcontext. Like

System.Web.HttpContext.Current().Request.ServerVariables("SERVER_NAME")

CJ.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AerosSagaCommented:
Dim en As System.Collections.IEnumerator

en = Request.Headers.GetEnumerator

While en.MoveNext
   Response.Write(CStr(en.Current) & "<br>")
End While

Or

Dim en As System.Collections.IEnumerator

en = Request.Headers.GetEnumerator

While en.MoveNext
   Response.Write(CStr(en.Current) & "<br>")
End While
0
bmcclearyAuthor Commented:
Thanks Aeros, but the problem is that I don't have access to the Request or Response objects.  When I put that code in my asmx page, it underscores bothe the Request and Response lines and states "Name 'Request' is not declared.".  My web service class inherits from System.Web.Services.WebService and the following are my imports clauses:

Imports System.Web.Services
Imports System.Text

Do I need another Imports statement?
0
AerosSagaCommented:
try imports system.web
0
bmcclearyAuthor Commented:
Thanks guys.  CJ, I didn't see your comment the first time, but that worked.  Aeros, thank you also, that seems to work as well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.