在C#中捕捉SOAP,在DLL中

在C#中捕捉SOAP,在DLL中,c#,soap,app-config,C#,Soap,App Config,我正在构建一个DLL,它应该被我正在构建的其他应用程序使用。 DLL功能的一部分是记录所有SOAP事务 我发现了关于如何在C#中捕获SOAP事务的这种解释。 我的问题是需要将以下内容添加到app.config(链接页面的末尾) 我不希望它成为所有使用我的DLL将其添加到app.config的用户的要求 在加载DLL时,有没有一种方法可以在运行时执行此操作?我在MSDN论坛上发现了一个类似的问题: 谢谢,这正是我想要的。第二步,我不知道这是不是你自己试过的东西。但是如果你知道了,你知道这是不

我正在构建一个DLL,它应该被我正在构建的其他应用程序使用。 DLL功能的一部分是记录所有SOAP事务

我发现了关于如何在C#中捕获SOAP事务的这种解释。

我的问题是需要将以下内容添加到app.config(链接页面的末尾)


我不希望它成为所有使用我的DLL将其添加到app.config的用户的要求


在加载DLL时,有没有一种方法可以在运行时执行此操作?

我在MSDN论坛上发现了一个类似的问题:


谢谢,这正是我想要的。第二步,我不知道这是不是你自己试过的东西。但是如果你知道了,你知道这是不是线程安全的吗。也就是说,如果我有两个线程,并且我在其中一个线程中运行这个“寄存器”。他会捕获第二根线制成的肥皂吗?我认为它不是线程安全的。您可以将其与
lock(obj){…}
同步,或者在启动线程之前执行此操作。
<system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="Encore.PayPal.Soap.TraceExtension, Encore.PayPal.Soap" priority="1" group="0" />
      </soapExtensionTypes>
    </webServices>
  </system.web>
/// <summary>  
/// 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>  
[ReflectionPermission(SecurityAction.Demand, Unrestricted = true)]  
public static void RegisterSoapExtension(Type type, int priority, PriorityGroup group)  
{  
    if (!type.IsSubclassOf(typeof(SoapExtension)))  
    {  
        throw new ArgumentException("Type must be derived from SoapException.", "type");  
    }  

    if (priority < 1)  
    {  
        throw new ArgumentOutOfRangeException("priority", priority, "Priority must be greater or equal to 1.");  
    }  

    // get the current web services settings...  
    WebServicesSection wss = WebServicesSection.Current;  

    // set SoapExtensionTypes collection to read/write...  
    FieldInfo readOnlyField = typeof(System.Configuration.ConfigurationElementCollection).GetField("bReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);  
    readOnlyField.SetValue(wss.SoapExtensionTypes, false);  

    // inject SoapExtension...  
    wss.SoapExtensionTypes.Add(new SoapExtensionTypeElement(type, priority, group));  

    // set SoapExtensionTypes collection back to readonly and clear modified flags...  
    MethodInfo resetModifiedMethod = typeof(System.Configuration.ConfigurationElement).GetMethod("ResetModified", BindingFlags.NonPublic | BindingFlags.Instance);  
    resetModifiedMethod.Invoke(wss.SoapExtensionTypes, null);  
    MethodInfo setReadOnlyMethod = typeof(System.Configuration.ConfigurationElement).GetMethod("SetReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);  
    setReadOnlyMethod.Invoke(wss.SoapExtensionTypes, null);  
} 
RegisterSoapExtension(typeof(TraceExtension), 1, PriorityGroup.Low);
PaypalClient cli = new PaypalClient();