.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Exception Handling in WCF REST Service Template 4.0

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :Windows Application
 

Hi,

I'm using WCF REST Service Template 4.0 and so far, I'm able to create RESTful Services with the said template successfully. Now, what I need is a nice way to handle exceptions in a RESTful Service. As far as I know, when an exception is thrown from a service method, the returned http status code to the client is 400 (Bad Request). My problem with this one is that I can't pass along a detailed information about the error(s) that occurred in my domain or business logic layer.

Examples of errors that I need to pass:

new ValidationResult { FieldName = "ProductName", Message = "Product Name is mandatory" };
new ValidationResult { FieldName = "ProductName", Message = "Product Name is too long" };
new ValidationResult { FieldName = "Price", Message = "Price should be greater than zero." };

So, my plan is to make all my services always return a successful request (with http status code 200) even if a domain layer error occurred.

When the service call is successful, it will return something like this:

<OperationResult>
    <StatusCode>200</StatusCode>
    <StatusDescription>Successful</StatusDescription>
    <Data>
        <Product>
            <Name>Sample Product</Name>
            <Price>1.00</Price>
            <Culture>en-


View Complete Post


More Related Resource Links

Exception Handling in WCF REST Service Template 4.0

  

Hi,

I'm using WCF REST Service Template 4.0 and so far, I'm able to create RESTful Services with the said template successfully. Now, what I need is a nice way to handle exceptions in a RESTful Service. As far as I know, when an exception is thrown from a service method, the returned http status code to the client is 400 (Bad Request). My problem with this one is that I can't pass along a detailed information about the error(s) that occurred in my domain or business logic layer.

Examples of errors that I need to pass:

new ValidationResult { FieldName = "ProductName", Message = "Product Name is mandatory" };
new ValidationResult { FieldName = "ProductName", Message = "Product Name is too long" };
new ValidationResult { FieldName = "Price", Message = "Price should be greater than zero." };

So, my plan is to make all my services always return a successful request (with http status code 200) even if a do

Exception handling in web service

  

I've written a web service and implented some exception handling withing my code. When I debug the services the exception handling works as planned, the catch clause handles the exception. The problem is that when I deploy to a production IIS 7 web server the exception handling in my code does not appear to be trapping any errors. It appears that IIS is trapping the errors and returns back a 500 error.

Is there a setting in web.config to prevent this from happening or is there some configuration change in II7 that need to happen to prevent my error handling from being overridden?

TIA


EL Exception Handling block and WCF custom Service Fault Exception

  

I am currently working on a project to integrate WCF custom fault along with enterprise library exception block. 

I was following Guy Burstein's blog for doing this :

http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/04/07/Shielding-WCF-Services-with-Exception-Handling-Application-Block-_2D00_-Part-1.aspx

This example only shows mapping for message and id. The message is of string data type and id is Guid data type.

But what if I have some other custom fields in my custom Fault object in which I have a CategoryID of type string to which I need to map the id of type Guid ?

When I try to do the mapping and propogate it, I get the value as null. Is there some way I could convert the Guid to string type while doing the mapping in EL?

[DataContract]

public class ServiceFault

{

    private

EXCEPTION HANDLING IN C#

  
Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

  
After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

SQL Server 2005 Try and Catch Exception Handling

  
I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

Error while using exception handling block el 4.1

  

Hi Folks,

 

i am trying to use tyhe exception handling block of Enterprise library 4.1.

 

I just createda polisy and used IndexOutOfRangeException and added a replace handler and a logging handler to it.

I am using the NotifyRethrow PostHandlingAction to the exception.

 

During runtime I am getting an exception on the HandleException event, The exception is added below:

 

 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:             catch (Exception ex)
Line 43:             {
Line 44:                 bool reThrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy");
Line 45:         

Service Station: More On REST

  

This month's column answers frequently asked questions about implementing REST.

Jon Flanders

MSDN Magazine July 2009


Data Points: SQL Server 2005 XML Support, Exception Handling, and More

  

SQL Server 2005 includes several important improvements to the Transact-SQL (T-SQL) language. One added feature is a new kind of trigger that fires when data definition language (DDL) statements run.

John Papa

MSDN Magazine May 2006


Error Handling: Throwing Custom Exception Types from a Managed COM+ Server Application

  

Exception handling semantics in .NET are based on type, so you can create custom exceptions that have their own properties and methods. In .NET, exceptions are first-class citizens, and since they're the built-in error handling mechanism, all .NET-compliant languages must support exceptions. In addition, COM+ services are available to .NET code as Enterprise Services, so you can leverage exceptions in your Enterprise Services design.In this article the author describes custom exceptions, throwing exceptions across COM interop boundaries, and working with Enterprise Services.

Bob DeRemer

MSDN Magazine March 2004


Looking for a simple Service and Console Client REST sample implementing BASIC authentication

  

Does anyone know of a C# code sample demonstrating WCF REST services and console test client with OperationContracts (GET and POST) implementing mutiple paramaters using BASIC authentication? Also, perhaps, using Fiddler as a test client as well? I have searched high and low for something like this, but have not had any success.


Multiple services in REST Collection WCF Service?

  

After I create a "REST Collection WCF Service" project, it contains one service "service.svc". Can I add multiple services to this project? There must be a way to do so. Otherwise, it does not make sense to create one project for each service.

 

My question is how to add a new service to an existing "REST Collection WCF Service" project?

 

Thanks a lot.


Cash Drawer - Method Open threw an exception - Windows Service

  
Hi All, I'm getting the following exception while calling Open method of Cash Drawer object. Method Open threw an exception.  Could not read the device name key's default value, or could not convert the Programmatic ID it holds into a valid Class ID. Code:   class Class1 { CashDrawer _uniCashDrawer1 = null; DeviceInfo cashDrawerDevice1 = null; PosExplorer posExplorer = new Microsoft.PointOfService.PosExplorer();   public void ClaimCashDrawer() { cashDrawerDevice1 = posExplorer.GetDevice("CashDrawer", "testDrawer"); if (cashDrawerDevice1 != null) { _uniCashDrawer1 = posExplorer.CreateInstance(cashDrawerDevice1) as CashDrawer; if (_uniCashDrawer1 != null) { _uniCashDrawer1.StatusUpdateEvent += new StatusUpdateEventHandler(UniCashDrawer1_StatusUpdateEvent); _uniCashDrawer1.Open(); _uniCashDrawer1.Claim(0); _uniCashDrawer1.DeviceEnabled = true; } } } }   Tha above code works fine if you put the code in WindowsApplication in all POS systems. The same is working if you put the code in Windows Service in all other POS systems. The same is not working if you put the code in Windows Service in Aures Galeo POS systems.  Thanks in advance. Ramakrishnan S

Serializing Linq to Entities for use in a REST Service

  
What would be the best approach to send data retrieved from Linq to Entities over a rest service? For example, if you have a Linq to Entities class, say Products from the Northwind database. I want to return a subset of the Products (based on a query on the model) back through a service. First a retrieve a List<Product> from the context, and then i need to serialize the data and send it over the wire. If I use the exact Linq to Entities class, then there is so much "garbage" that it either fails outright (from a circular reference) or you are wasting bandwith. What is a design to overcome this? Create POCO objects for each linq to entities class you want to send and create custom code to tranform each object in the list to the POCO object? This is the only way I can see doing it, although it would be very tedius to create and maintain (unless some custom code generation was created). Is there a better approach? clients

While calling Web service gets exception "The request failed with HTTP status 401: Unauthorized"

  
Hi All, I created a ASP.NET web service, which was hosted on default visual studioserver, and on excecution of webservice it run .exe file which in turn update xml file. Now i hosted this webservice on IIS 6.0 server, and when i run the service, itfails to execute the exe.When i run it on debug mode, i never get any exception.Code...public string HelloWorld()    {        Process myProcess = new Process();        try        {            myProcess.StartInfo.UseShellExecute = false;            // You can start any process,             myProcess.StartInfo.FileName = @"E:\Projects\some.exe";            myProcess.StartInfo.CreateNoWindow = true;            myProcess.Start();            myProcess.Close();            myProcess.Dispose();            return "Suceess";         }&n
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend