Web service support for HEAD requests?

Last post 07-06-2009 5:42 PM by johnwsaunders3. 7 replies.

Sort Posts:

  • Web service support for HEAD requests?

    07-02-2009, 5:06 PM
    • Member
      1 point Member
    • c.kellogg
    • Member since 07-02-2009, 8:37 PM
    • Posts 6

    I've been poking around the web for a couple of hours trying to find an answer to this one.  I'm in the process of building a web service for one of our clients.  It uses cookieless sessions, so the client needs a way get the redirected URL containing the session id.  They would like to do this with a HEAD request. For some reason, I can't get this to work in my test client.  Here's my code:

            Dim req As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://localhost/webserv/webserv.asmx/Ping")
            With req
                .Method = "HEAD"
                .Timeout = 20000
            End With
            Dim res As System.Net.HttpWebResponse = req.GetResponse
            txtAnswer.Text = res.ResponseUri.AbsoluteUri
            res.Close()
    

    Submitting this results in the "(500) Internal Server Error" on the line that calls GetResponse.  If I change the Method to "GET", it works, returning the response url.  The Ping method above is an empty Sub so there's no code in there to fail.

    I've also discovered that if I remove the method from the URL leaving http://localhost/webserv/webserv.asmx, I get the "(405) Method Not Allowed" error.

    Is it possible to perform a HEAD request against a web service?  Do I need to do something in the web service or IIS config?  This is running on an older machine (IIS 5.0).  Any help would be much appreciated.

    ck

  • Re: Web service support for HEAD requests?

    07-05-2009, 7:34 PM

    Please post some code from the web service. If you can't post your actual code, then try this with a "hello, world" service, and post the code to that.

    Please don't make us guess. You're going to get much better answers if the people answering don't have to guess.

    John Saunders
  • Re: Web service support for HEAD requests?

    07-06-2009, 9:16 AM
    • Member
      1 point Member
    • c.kellogg
    • Member since 07-02-2009, 8:37 PM
    • Posts 6

    Hey John, thanks for the tip.  I've gone ahead and created a new web service, WebService1, containing the HelloWorld method.  The only change I made was to enable sessions so the code looks like this:

    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class WebService1
        Inherits System.Web.Services.WebService
    
        <WebMethod(EnableSession:=True)> _
        Public Function HelloWorld() As String
            Return "Hello World"
        End Function
    
    End Class

    I recompiled the web service and updated my client code to use the new service/method.

        Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click
            Dim req As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://localhost:54303/ECTools/WebService1.asmx/HelloWorld")
            With req
                .Method = "HEAD"
                .Timeout = 20000
            End With
            Dim res As System.Net.HttpWebResponse = req.GetResponse
            txtAnswer.Text = res.ResponseUri.AbsoluteUri
            res.Close()
        End Sub
    

    Still experiencing the same behavior.  Thanks.

  • Re: Web service support for HEAD requests?

    07-06-2009, 11:40 AM

    Excellent. Now, take a look in the Application event log on the server to see if ASP.NET has entered any indication of the reason for the server error.

    John Saunders
  • Re: Web service support for HEAD requests?

    07-06-2009, 12:19 PM
    • Member
      1 point Member
    • c.kellogg
    • Member since 07-02-2009, 8:37 PM
    • Posts 6

    I'll go ahead and post the contents of the warning: 

    Event code: 3005 
    Event message: An unhandled exception has occurred. 
    Event time: 7/6/2009 9:03:53 AM 
    Event time (UTC): 7/6/2009 1:03:53 PM 
    Event ID: 94d32036ad5a4baaa9a357fe7d59bddd 
    Event sequence: 93 
    Event occurrence: 8 
    Event detail code: 0 
     
    Application information: 
        Application domain: /LM/W3SVC/3/Root-97-128910392467973398 
        Trust level: Full 
        Application Virtual Path: / 
        Application Path: C:\Development_Web_Sites\ZZCOMOP\ 
        Machine name: TEST 
     
    Process information: 
        Process ID: 2872 
        Process name: aspnet_wp.exe 
        Account name: TEST\ASPNET 
     
    Exception information: 
        Exception type: WebException 
        Exception message: The remote server returned an error: (500) Internal Server Error. 
     
    Request information: 
        Request URL: http://localhost:54302/ECToolsApp.aspx 
        Request path: /ECToolsApp.aspx 
        User host address: 172.16.10.110 
        User:  
        Is authenticated: False 
        Authentication Type:  
        Thread account name: TEST\ASPNET 
     
    Thread information: 
        Thread ID: 5 
        Thread account name: TEST\ASPNET 
        Is impersonating: False 
        Stack trace:    at System.Net.HttpWebRequest.GetResponse()
       at ECToolsApp.btnTest_Click(Object sender, EventArgs e) in C:\Development_Web_Sites\ZZCOMOP\ECToolsApp.aspx.vb:line 176
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     
     
    Custom event details: 
     

    There were no custom details.  The error is occurring when I try to call GetResponse with the Method set to HEAD.

  • Re: Web service support for HEAD requests?

    07-06-2009, 4:38 PM

    Sorry, I meant on the server running the web service.

    Server error 500 is from the server. It usually means that there was an unhandled exception.

    John Saunders
  • Re: Web service support for HEAD requests?

    07-06-2009, 5:34 PM
    • Member
      1 point Member
    • c.kellogg
    • Member since 07-02-2009, 8:37 PM
    • Posts 6

    Ah, I see...  The web service and test client are actually running on the same server.  I didn't notice before that each request was generating two errors.  Here's the details on the web service error:

    Event code: 3005 
    Event message: An unhandled exception has occurred. 
    Event time: 7/6/2009 9:03:53 AM 
    Event time (UTC): 7/6/2009 1:03:53 PM 
    Event ID: 90d1822f05ac44b888c3566d939865de 
    Event sequence: 15 
    Event occurrence: 2 
    Event detail code: 0 
     
    Application information: 
        Application domain: /LM/W3SVC/4/Root/ECTools-98-128913583052484232 
        Trust level: Full 
        Application Virtual Path: /ECTools 
        Application Path: C:\Development_Web_Sites\ZZCOMPCLT\ECTools\ECTools\ 
        Machine name: TEST 
     
    Process information: 
        Process ID: 2872 
        Process name: aspnet_wp.exe 
        Account name: TEST\ASPNET 
     
    Exception information: 
        Exception type: InvalidOperationException 
        Exception message: Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'. 
     
    Request information: 
        Request URL: http://localhost:54303/ECTools/WebService1.asmx/HelloWorld 
        Request path: /ECTools/WebService1.asmx/HelloWorld 
        User host address: 172.16.10.228 
        User:  
        Is authenticated: False 
        Authentication Type:  
        Thread account name: TEST\ASPNET 
     
    Thread information: 
        Thread ID: 14 
        Thread account name: TEST\ASPNET 
        Is impersonating: False 
        Stack trace:    at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
       at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
       at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
       at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
     
     
    Custom event details: 
    

    Is the web server trying to process the request as a GET even though the Method is set to HEAD?  Does my request have to be something other than an HttpWebRequest?  Or maybe I should be calling something other than GetResponse.  I'm going to try some things along these lines, but if you have any ideas, please let me know.

  • Re: Web service support for HEAD requests?

    07-06-2009, 5:42 PM
    Answer

    I'm very sorry I didn't notice before. I guess I thought since you were using HEAD, that you were using an AJAX-style service.

    You're just using a plain, old, (legacy) ASMX service, which supports SOAP and maybe GET and POST. And nothing else.

    Sorry. Can't happen, at least not with (legacy) ASMX services (See ASMX Web Services are a “Legacy Technology”).

    However, this does work in WCF.

    John Saunders
Page 1 of 1 (8 items)