Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the exception handling of WCF

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly talks about "what is the exception handling of WCF". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the exception handling of WCF"?

Introduction

WCF (Windows Communication Foundation)-exception handling: general Exception handling, FaultException and FaultException throwing and handling, using IErrorHandler to handle exceptions.

Here is the third exception: throwing and handling of FaultException

1. Strongly typed an SOP error class, which needs to be passed with [DataContract] / error message entity class (for error contract FaultContract) / [DataContract] public class FaultMessage {/ DataMember] public string Message {get; set;} / error code / [DataMember] public int ErrorCode {get; set Specify the error type [ServiceContract] public interface IHello {[OperationContract] [FaultContract (typeof (FaultMessage))] void HelloFaultExceptionGeneric () with [FaultContract] error contract in the operation agreement. 3. In the implementation code, define a method that can throw an exception of FaultException / Hello class / public class Hello: IHello {/ throw FaultException exception / public void HelloFaultExceptionGeneric () {throw new FaultException (new FaultMessage {Message = "throw FaultException exception", ErrorCode =-1}, "for testing FaultException") Fourth, the exception of FaultException can be caught in the client. FaultMessage is accessed with the Detail attribute. Protected void btnHelloFaultExceptionGeneric_Click (object sender, EventArgs e) {ExceptionService.HelloClient proxy = new ExceptionService.HelloClient (); try {proxy.HelloFaultExceptionGeneric ();} catch (System.ServiceModel.FaultException ex) {lblMsg.Text = string.Format ("error Code: {0}; error message: {1} Error reasons: {2} ", ex.Detail.ErrorCode.ToString (), ex.Detail.Message, ex.Reason.ToString ();} finally {proxy.Close ();}} so far, I believe you have a deeper understanding of" what is the exception handling of WCF ". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report