zoukankan      html  css  js  c++  java
  • asp.net中WebService 捕获全局异常

    在WebService 中,使用IHttpHand 捕获不到全局异常,这时候,需要使用  SoapExtension (此方法仅对引用有效,对使用ajax等方法访问webservice 无效)

    代码如下

     public class SoapExceptionHandler : System.Web.Services.Protocols.SoapExtension
        {
            public override object GetInitializer(Type serviceType)
            {
                return null;
            }
    
            public override object GetInitializer(System.Web.Services.Protocols.LogicalMethodInfo methodInfo, System.Web.Services.Protocols.SoapExtensionAttribute attribute)
            {
                return null;
            }
    
            public override void Initialize(object initializer)
            {
               
            }
    
            public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
            {
                if (message.Stage == SoapMessageStage.AfterSerialize)
                {
                    if (message.Exception != null)
                    {
                        AppLog.Info(message.Exception.InnerException);
                        //LogUtil.Log.Error(message.Exception.InnerException);
                    }
                }
            }
        }

    同时,需要在web.config里面进行配置

    找到<webServices> 节点

    添加如下配置

     <soapExtensionTypes>
            <add type="Eway.HR.WebService.SoapExceptionHandler, Eway.HR.WebService" priority="1" group="High" />
          </soapExtensionTypes>

    这时候,如果直接使用vs直接用网页打开进行调试,是不会有效果的,因为这种方式不是一个完整的soap,

    可以使用 WebserviceStudio 进行测试,下载地址:https://archive.codeplex.com/?p=WebserviceStudio

    WebserviceStudio

  • 相关阅读:
    继续学习:C语言关键字
    继续学习C:运算符
    C语言小程序(八)、统计字母个数
    C语言小程序(七)、石头剪刀布
    飞思卡尔总结
    [原]NYOJ-子串和44
    C++函数重载详解
    趣味Shell
    C语言小程序(六)、数组操作
    C语言小程序(五)、数组查询
  • 原文地址:https://www.cnblogs.com/chcong/p/11423054.html
Copyright © 2011-2022 走看看