Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Moving from web.config to HttpApplication
Message
From
28/01/2015 09:36:04
 
 
General information
Forum:
ASP.NET
Category:
Web Services
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01614430
Message ID:
01614473
Views:
18
>No idea if this works but : http://www.justskins.com/forums/programatically-register-soapextensions-77036.html
>But why do you want to do this?

I have added the following in my Global class:
    Private Shared Sub InjectTraceExtensionToConfig()
        Dim assBase As Assembly
        Dim webServiceConfig As Type
        Dim currentProp As Object
        Dim propInfo As PropertyInfo
        Dim value As Object()
        Dim myType As Type
        Dim objArray As Object()
        Dim myObj As Object
        Dim myField As FieldInfo

        Try
            assBase = GetType(System.Web.Services.Protocols.SoapExtensionAttribute).Assembly
            webServiceConfig = assBase.[GetType]("System.Web.Services.Configuration.WebServicesCon figuration")

            If webServiceConfig Is Nothing Then
                Throw New Exception("Error ...")
            End If

            currentProp = webServiceConfig.GetProperty("Current").GetValue(Nothing, Nothing)
            propInfo = webServiceConfig.GetProperty("SoapExtensionTypes")
            value = DirectCast(propInfo.GetValue(currentProp, Nothing), Object())
            myType = value.[GetType]().GetElementType()
            objArray = DirectCast(Array.CreateInstance(myType, CInt(value.Length) + 1), Object())
            Array.Copy(value, objArray, CInt(value.Length))

            myObj = Activator.CreateInstance(myType)
            myField = myType.GetField("Type")
            myField.SetValue(myObj, GetType(TraceExtension))
            objArray(CInt(objArray.Length) - 1) = myObj
            propInfo.SetValue(currentProp, objArray, Nothing)
        Catch ex As Exception
        End Try
    End Sub
The Global class is called from Global.asax:
< @ Application Language="VB" Inherits="Framework.GlobalBase"%>
But, as is, it will not do anything. Something has to trigger this method. This is where I am not sure about the proper way to establish a trigger here. When this is in the web.config. the trigger is done by .NET. But, in the code, there is a missing link here.

The reason I want to put this in the code is to have the control over it. Everything that most of the people usually put in Global.asax, I put it in my Global class. Then, from Global.asax, the only thing I have to put is the one line you see above. By that, I do not have to worry about setting up web.config wherever I need a Web site or Web service application. I control everything from the framework and that makes it easier to migrate to another development environment when time comes. This Global.asax is to proprietary to .NET.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform