在DLL中捕获C#中的SOAP
发布时间:2020-12-14 05:31:16 所属栏目:Windows 来源:网络整理
导读:我正在构建一个DLL,应该由我正在构建的其他一些应用程序使用. DLL功能的一部分是记录所有SOAP事务. 我已经找到了关于如何在C#中捕获SOAP事务的解释. https://web.archive.org/web/20160402053148/http://blog.encoresystems.net/articles/how-to-capture-soa
我正在构建一个DLL,应该由我正在构建的其他一些应用程序使用.
DLL功能的一部分是记录所有SOAP事务. 我已经找到了关于如何在C#中捕获SOAP事务的解释. 我的问题是它需要将以下内容添加到app.config(链接的页面末尾). <system.web> <webServices> <soapExtensionTypes> <add type="Encore.PayPal.Soap.TraceExtension,Encore.PayPal.Soap" priority="1" group="0" /> </soapExtensionTypes> </webServices> </system.web> 我不希望它是所有使用我的DLL将其添加到app.config的要求. 有没有办法在DLL加载时动态执行此操作? 解决方法
我在MSDN论坛上发现了类似的问题:
Programmatically registering a SOAP Extension
/// <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,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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-server-2008-r2 – 为什么我们的服务器上只有16 GB
- Windows 10 子系统 Ubuntu 中安装 FastAdmin
- Error: EACCES: permission denied, mkdir
- windows – 内存释放例程是否触及正被释放的块?
- windows – IE6和IE7 Standalone:它们以不同的方式呈现什么
- Windows – 替代远程桌面软件
- ms-access – MsysObjects值-32758,-32757和3(Microsoft Ac
- Windows Azure:无法将34 MB文件上载到blob
- 如何在Windows上集成PHP和R?
- xaml – 如何在uwp应用程序上正确启用dpi-scaling
推荐文章
站长推荐
热点阅读