u84six
u84six

Reputation: 4941

What is a typical way to create your own static error code list in C# ASP.NET?

I'm trying to find the most efficient way to create an error code list for my web service so that when certain problems occur my client app will know what it is. I don't want to return a lengthy string, so I'd rather use simple numbers. I'm just curious as to how some of you would create your own error code table for an asp.net app. Would you just create a bunch of constants, or an enum type in your web service? Or would you create some kind of class that only holds constants? I'm not sure what the best way to handle this would be. I don't want to instantiate a class just for errors codes every time someone hits the web service.

Edit: I should have been a little more specific. The web service does use data contracts, but doesn't use WCF. I'm using a home brewed implementation of JSON-RPC, which requires that an error code be stored in the response json.

Upvotes: 0

Views: 317

Answers (3)

PHeiberg
PHeiberg

Reputation: 29811

Assuming you mean the WCF type of web services, you can use FaultContract to specify different errors and how to handle them on the client side.

Upvotes: 1

user1704366
user1704366

Reputation:

Just a thought for you, but ... don't worry about creating the class, the garbage collector will dispose of it when you no longer need it, and if you use it often enough, then it will stay in the applications memory in Jit form so it will be performant!

Personally, I try to not worry that much about "performance" to the extreme as it is typically not even noticeable...

However, if you are worried, then you should look at creating a single static class which can be used application wide and instantiated on start up and hold the constants there as then a single in memory class will be used saving on memory and any perceived performance hit.

Best wishes

Matthew

Upvotes: 1

Lews Therin
Lews Therin

Reputation: 10995

You are not programming in C, why error codes? Web service is broad here but I assume you mean WCF?

Anyway WCF throws a FaultException which bubbles up to the client and this is a lot better than using error codes. Error codes don't tell me anything, and can be prove to be a PITA to maintain later. But if a FaultException occurs there are lots of information that I can glean from the object.

FaultException (or SomeException) > Error Code.

Upvotes: 0

Related Questions