博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在ASP.NET中使用SOAP Extensions捕获WebService异常
阅读量:6937 次
发布时间:2019-06-27

本文共 1281 字,大约阅读时间需要 4 分钟。

原文:

Application_Error不能捕获的异常

[WebMethod]        public string HelloWorld()        {            throw new Exception("this exption can't be handled by Application_Error Method");            return "Hello World";        }
定义Application_Error将不能捕获这个异常.
原因需要了解一下SOAP请求的在ASP.NET的生命周期.
 

 

Process Message过程调用WebMethod时如果产生SoapException,SoapHeaderException 被序列化后,返回在SOAP <Fault>结点.

使用SOAP extension扩展处理Process Message过程产生的异常

我们可以SOAP Extension处理

 
ContractedBlock.gifExpandedBlockStart.gifCode
public class SoapExceptionHandler : System.Web.Services.Protocols.SoapExtension
    {
        
public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
        {
            
if (message.Stage == SoapMessageStage.AfterSerialize)
            {
                
if (message.Exception != null)
                {
                    LogUtil.Log.Error(message.Exception.InnerException);
                }
            }
        }
        
public override object GetInitializer(Type serviceType)
        {
            
return null;
        }
        
public override object GetInitializer(
            LogicalMethodInfo methodInfo,
            SoapExtensionAttribute attribute)
        {
            
return null;
        }
        
public override void Initialize(object initializer) 
        {
        }
    }
在Web.config system.web结点中配置
 
ContractedBlock.gifExpandedBlockStart.gifCode
        <webServices>
            
<soapExtensionTypes>
                
<add type="Elplan.App.SoapExceptionHandler, Elplan.App" priority="1" group="High" />
            
</soapExtensionTypes>
        
</webServices>
 

调试:

如果使用VS直接运行调试asmx,是不可以的.(因为...它不是一个完整的SOAP请求.)可使用WebServiceStudio.

相关地址: 

参考文章:

转载地址:http://bwwnl.baihongyu.com/

你可能感兴趣的文章
左神算法进阶班3_1构造数组的MaxTree
查看>>
SQL Server中的锁类型及用法(转载)
查看>>
CodeVS 1008 选数(DFS)
查看>>
SQL Server日常积累
查看>>
C++强制类型转换
查看>>
搭建FTP服务器 window7
查看>>
并发编程下的性能定律(翻译)
查看>>
cssText文本格式化
查看>>
新建koa2项目
查看>>
Phoenix 索引生命周期
查看>>
I,P,B帧和PTS,DTS的关系
查看>>
JavaOO练习:违规管理系统
查看>>
继续开始列车式的生活
查看>>
String的属性和方法
查看>>
hdu-1800
查看>>
读写锁-锁粒度
查看>>
C#_delegate - 用委托实现事件,Display和Log类都使用Clock对象
查看>>
java.net.BindException: 权限不够
查看>>
《c程序设计语言》读书笔记-字符型0-9转为数字0-9
查看>>
公务员队伍开始动荡了吗?
查看>>