Question

During Application_BeginRequest any Global.asax or System.Web.Services.WebService event, is there a reliable way to instantiate or examine the intended web service method using reflection? I need to determine what the value of attributes are on the web service being called.

I'm pretty sure the neccessary information is available in HttpContext.Current.Request to do this, but I'm not familiar enough with reflection syntax.

GLOBAL ASAX

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    Dim InboundRequest As HttpRequest = HttpContext.Current.Request

    'ASSUMING REQUEST IS FOR DemoService.asmx/ExampleMethod'

    'NEED CODE HERE TO DETERMINE '
    'WHAT THE VALUE OF THE "ScriptMethod" ATTRIBUTE IS'
End Sub

WEB SERVICE

<ToolboxItem(False), ScriptService()> _
Public Class DemoService
    Inherits System.Web.Services.WebService

    <WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function ExampleMethod()
        Return "Hello World"
    End Function
End Class

VB.Net or C# answers are welcome, I can convert as neccessary

No correct solution

OTHER TIPS

You could, but I think it'd be better to do whatever you are planning to do in the PreRequestHandlerExecute event as you'll have the web service object instance created by asp.net already. Just remember that this event is fired for all types of handlers (pages, web services, generic, etc).

If you do want to go this route on your own, then you'd just need to do Activator.CreateInstance(type) where type is the web service type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top