C# 如何在应用程序启动请求期间使用反射来实例化web服务方法?
在C# 如何在应用程序启动请求期间使用反射来实例化web服务方法?,c#,asp.net,.net,vb.net,asmx,C#,Asp.net,.net,Vb.net,Asmx,在Application\u BeginRequestanyGlobal.asax或System.Web.Services.WebService事件期间,是否有可靠的方法使用反射实例化或检查预期的Web服务方法?我需要确定被调用的web服务的属性值 我很确定必要的信息可以在HttpContext.Current.Request中找到,但我对反射语法不够熟悉 全球ASAX Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
Application\u BeginRequest
anyGlobal.asax
或System.Web.Services.WebService
事件期间,是否有可靠的方法使用反射实例化或检查预期的Web服务方法?我需要确定被调用的web服务的属性值
我很确定必要的信息可以在HttpContext.Current.Request
中找到,但我对反射语法不够熟悉
全球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
网络服务
<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
_
公共服务
继承System.Web.Services.WebService
_
公共函数ExampleMethod()
返回“你好,世界”
端函数
末级
欢迎使用VB.Net或C#答案,我可以根据需要进行转换您可以,但我认为最好在
PreRequestHandlerExecute
事件中执行您计划执行的任何操作,因为您已经有了由asp.Net创建的web服务对象实例。请记住,此事件是针对所有类型的处理程序(页面、web服务、通用等)触发的
如果您真的想自己走这条路,那么您只需要执行Activator.CreateInstance(type),其中type是web服务类型。您有覆盖该事件的示例吗?您可以将其放在global.asax中。这就像BeginRequest事件一样,您能否更具体地说明我在
应用程序\u PreRequestHandlerExecute
期间可以访问哪些我在应用程序\u BeginRequest
中无权访问的内容?EventArgs仍然为空,我在当前上下文(即HttpContext.current.Handler)的上下文或请求中没有看到任何特殊内容。该属性中的对象将是您的web服务(假设它是web服务处理程序)