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

  • 相关阅读:
    Java服务停止与开启
    跨域,php后端处理
    Mac 504 gateway timeout nginx
    Tp3.2 多数据库链接
    Redis 设置密码
    Redis 如何对外访问 lnmp安装
    tensorflow gpu安装
    ngx_http_upstream_check_module
    Nginx负载均衡+监控状态检测
    springboot+log4j2+slf4j控制台打印带sql日志
  • 原文地址:https://www.cnblogs.com/chcong/p/11423054.html
Copyright © 2011-2022 走看看