Solved

Accessing Host Header within Web Services Method

Posted on 2004-11-01
395 Views
Last Modified: 2012-06-27
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!
0
Question by:bmccleary
    5 Comments
     
    LVL 22

    Accepted Solution

    by:
    Try using the current httpcontext. Like

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

    CJ.

    0
     
    LVL 17

    Expert Comment

    by:AerosSaga
    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
     

    Author Comment

    by:bmccleary
    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
     
    LVL 17

    Assisted Solution

    by:AerosSaga
    try imports system.web
    0
     

    Author Comment

    by:bmccleary
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now