Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Moving from web.config to HttpApplication
Message
De
28/01/2015 10:48:23
 
 
À
28/01/2015 10:40:04
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01614430
Message ID:
01614486
Vues:
14
>This approach works.
>
>In the Global class, I have added the Application_Start(), as suggested by Viv, and use a new method which accepts my TraceExtension class type, the group and the priority:
>
>
>    Sub Application_Start()
>        RegisterSoapExtension(GetType(TraceExtension), 1, 0)
>    End Sub
>
>
>In the Global class, I added this new method to establish a hook to the SOAP enveloppe:
>
>
>    ''' Programatically registers a <see cref="SoapExtension"/> at runtime with the specified  
>    ''' <see cref="SoapExtensionTypeElement.Priority"/> and <see cref="SoapExtensionTypeElement.Group"/> settings.  
>    ''' </summary>  
>    ''' <param name="type">The <see cref="Type"/> of the <see cref="SoapExtension"/> to register.</param>  
>    ''' <param name="priority">  
>    ''' A value that indicates the relative order in which this SOAP extension runs when multiple SOAP extensions are  
>    ''' specified. Within each group the priority attribute distinguishes the overall relative priority of the SOAP   
>    ''' extension. A lower priority number indicates a higher priority for the SOAP extension. The lowest possible   
>    ''' value for the priority attribute is 1.  
>    ''' </param>  
>    ''' <param name="group">  
>    ''' The relative priority group (e.g. Low or High) in which this SOAP extension runs when multiple SOAP extensions   
>    ''' are configured to run.  
>    ''' </param>  
>    <System.Security.Permissions.ReflectionPermission(System.Security.Permissions.SecurityAction.Demand, Unrestricted:=True)> _
>    Public Shared Sub RegisterSoapExtension(type As Type, priority As Integer, group As System.Web.Services.Configuration.PriorityGroup)
>
>        If Not type.IsSubclassOf(GetType(System.Web.Services.Protocols.SoapExtension)) Then
>            Throw New ArgumentException("Type must be derived from SoapException.", "type")
>        End If
>
>        If priority < 1 Then
>            Throw New ArgumentOutOfRangeException("priority", priority, "Priority must be greater or equal to 1.")
>        End If
>
>        ' get the current web services settings...  
>        Dim wss As System.Web.Services.Configuration.WebServicesSection = System.Web.Services.Configuration.WebServicesSection.Current
>
>        ' set SoapExtensionTypes collection to read/write...  
>        Dim readOnlyField As System.Reflection.FieldInfo = GetType(System.Configuration.ConfigurationElementCollection).GetField("bReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
>
>        readOnlyField.SetValue(wss.SoapExtensionTypes, False)
>
>        ' inject SoapExtension...  
>        wss.SoapExtensionTypes.Add(New System.Web.Services.Configuration.SoapExtensionTypeElement(type, priority, group))
>
>        ' set SoapExtensionTypes collection back to readonly and clear modified flags...  
>        Dim resetModifiedMethod As System.Reflection.MethodInfo = GetType(System.Configuration.ConfigurationElement).GetMethod("ResetModified", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
>
>        resetModifiedMethod.Invoke(wss.SoapExtensionTypes, Nothing)
>
>        Dim setReadOnlyMethod As System.Reflection.MethodInfo = GetType(System.Configuration.ConfigurationElement).GetMethod("SetReadOnly", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
>
>        setReadOnlyMethod.Invoke(wss.SoapExtensionTypes, Nothing)
>    End Sub
>
That looks simpler than the code I found.....

BTW re: the config problem in the other thread: Try:
<add type="Framework.TraceExtension,Framework" priority="1" group="High"/>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform