在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

相关文章:

  • 2021-09-26
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2021-08-22
  • 2021-08-23
  • 2021-08-17
相关资源
相似解决方案