2014-02-14 19 views
1

期間 Application_BeginRequest 任何Global.asaxSystem.Web.Services.WebService事件,有沒有一種可靠的方法來實例化或檢查使用反射的預期的Web服務方法?我需要確定被調用的Web服務中屬性的值。如何在Application_BeginRequest中使用反射來即時使用Web服務方法?

我很確定必要的信息在HttpContext.Current.Request可用,但我對反射語法不夠熟悉。

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或C#的答案是受歡迎的,我可以爲neccessary

回答

0

你可以轉換,但我認爲在PreRequestHandlerExecute事件中做任何你打算做的事情會更好,因爲y你會有asp.net創建的web服務對象實例。請記住,這個事件是爲所有類型的處理程序(頁面,Web服務,通​​用等)觸發的。

如果您確實想自己走這條路線,那麼您只需要執行Activator.CreateInstance(type),其中type是Web服務類型。

+0

你有覆蓋該事件的例子嗎? –

+0

你可以把它放在global.asax中。它就像BeginRequest事件 –

+0

您能否更具體地瞭解我在'Application_PreRequestHandlerExecute'期間訪問的內容,我無法在'Application_BeginRequest'中訪問? EventArgs仍然是空的,我沒有看到上下文或請求中的任何特殊內容 –

相關問題