cool hit counter [C#] Adding a reference to throw and catch clean WebService exceptions_Intefrankly

[C#] Adding a reference to throw and catch clean WebService exceptions

Description: [ Clean] refers to the ex. that the client gets when catching an exception thrown by the WebService (hereafter WS). Message is the exception message thrown in the WS method, without any "impurities".

Prerequisite. You have writing rights to WS. That is, if you're tuning a WS written by someone else, then maybe the only way to get a clean ex. is through string processing. Message.

First, see the example.

- WS Method.

/// <summary>
 /// Test WS throws exceptions
/// </summary>
/// <param name="isSoapEx">because oftrue just throw outSoapException, Otherwise, throwException</param>
/// <param name="errMsg"> Customizing Exception Messages</param>
public string Test(bool isSoapEx, string errMsg)
    throw isSoapEx
        ? new SoapException(errMsg, SoapException.ServerFaultCode)
        : new Exception(errMsg);

- Client call.

You can see that if WS throws an Exception, the client gets the ex. Message is what contains "impurities", so one of the keys to getting a clean anomaly message is.

WS is going to throw a SoapException exception.

This is why it says you have the right to write to the WS, because someone else's WS that throws something other than a SoapException, you get the innately impurity-laden ex. Message, it needs to be processed in some way to work.

What I just said is one of the essentials, that means that even if WS throws a SoapException, it is possible to get an unclean ex. Message, as shown in the figure.

This is caused by the ASP.NET application's [custom error message] being set to "Off". Set the mode property of the configurationsystem.webcustomErrors node in WS's web.config to "On" or "RemoteOnly". . As pictured.

So, to summarize, with what I know so far, to get a clean ex. on the client side. Message, the key to this is twofold.

1. WS should encapsulate the exception as SoapException before throwing it

2、WS's [Custom Error Message] cannot be set to Off


1、Selfdriving accident driverless concept sends itself a cool song
2、Xiamen Big data to help build a smart city
3、Notice from the Legal and Price Control Center of Guangzhou Zhiwan Artificial Intelligence Technology Co
4、When will artificially intelligent robots which can do anything come to life
5、A letter of apology from 360 Fast Video

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送