- 1、本文档共16页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
《WCF教程10》.doc
[原创]我的WCF之旅(10):如何在WCF进行Exception Handling
在任何Application的开发中,对不可预知的异常进行troubleshooting时,异常处理显得尤为重要。对于一般的.NET系统来说,我们简单地借助try/catch可以很容易地实现这一功能。但是对于 一个分布式的环境来说,异常处理就没有那么简单了。按照面向服务的原则,我们把一些可复用的业务逻辑以Service的形式实现,各个Service处于一个自治的环境中,一个Service需要和另一个Service进行交互,只需要获得该Service的描述(Description)就可以了(比如WSDL,Schema和Strategy)。借助标准的、平台无关的通信构架,各个Service之间通过标准的Soap Message进行交互。Service Description、Standard Communication Infrastructure、Soap Message based Communication促使各Service以松耦合的方式结合在一起。但是由于各个Service是自治的,如果一个Service调用另一个Service,在服务提供方抛出的Exception必须被封装在Soap Message中,方能被处于另一方的服务的使用者获得、从而进行合理的处理。下面我们结合一个简单的Sample来简单地介绍我们可以通过哪些方式在WCF中进行Exception Handling。
一、传统的Exception Handling
我们沿用我们一直使用的Calculator的例子和简单的4层构架:
1.??? Service Contract- Artech.ExceptionHandling.Contract
using?System;using?System.Collections.Generic;using?System.Text;using?System.ServiceModel;namespace?Artech.ExceptionHandling.Contract{????[ServiceContract]????public?interface?ICalculator????{????????[OperationContract]????????double?Divide(double?x,?double?y);????}}
定义了一个单一的进行除法运算的Operation。
2.??? Service:Artech.ExceptionHandling.Service. CalculatorService
using?System;using?System.Collections.Generic;using?System.Text;using?Artech.ExceptionHandling.Contract;namespace?Artech.ExceptionHandling.Service{????public?class?CalculatorService:ICalculator????{????????ICalculator?Members#region?ICalculator?Members????????public?double?Divide(double?x,?double?y)????????{????????????if?(y?==?0)????????????{????????????????throw?new?DivideByZeroException(Divide?by?zero);????????????}????????????return?x?/?y;????????}????????#endregion????}}
如果被除数是零,抛出一个DivideByZeroException Exception。
3.??? Service Hosting
Configuration:
?xml?version=1.0?encoding=utf-8??configuration????system.serviceModel????????behaviors????????????serviceBehaviors????????????????behavior?name=calculatorServiceBehavior????????????????????serviceMetadata?httpGetEnabled=true?/????????????????/behavior????????????/serv
您可能关注的文档
- 《transformation of yeast by LiAc ssdna peg method》.pdf
- 《TS16949标准和内审员培训》.ppt
- 《TSC_TTP-244ME_Plus条码打印机操作手册》.pdf
- 《TT100超声波测厚仪使用说明书》.pdf
- 《TThe man in the water课件》.ppt
- 《TWI_Welding_Training_1》.ppt
- 《TWI_Welding_Training_5》.ppt
- 《Two-Wire Peripheral Expansion for the AT89C2051 Microcontroller》.pdf
- 《UDM Systems Die sep wafer cleaning - bil》.ppt
- 《Unit 3 Weather》.doc
- 10《那一年,面包飘香》教案.docx
- 13 花钟 教学设计-2023-2024学年三年级下册语文统编版.docx
- 2024-2025学年中职学校心理健康教育与霸凌预防的设计.docx
- 2024-2025学年中职生反思与行动的反霸凌教学设计.docx
- 2023-2024学年人教版小学数学一年级上册5.docx
- 4.1.1 线段、射线、直线 教学设计 2024-2025学年北师大版七年级数学上册.docx
- 川教版(2024)三年级上册 2.2在线导航选路线 教案.docx
- Unit 8 Dolls (教学设计)-2024-2025学年译林版(三起)英语四年级上册.docx
- 高一上学期体育与健康人教版 “贪吃蛇”耐久跑 教案.docx
- 第1课时 亿以内数的认识(教学设计)-2024-2025学年四年级上册数学人教版.docx
文档评论(0)