WCF Rest Error Handling -


i'm having mind blowing problem using wcf 4.0 restful service. trying make rest service return, in case of error, xml document describing problem ex :

    <errorhandler>         <cause>resource not  available</cause>         <errorcode>111103</errorcode>     </errorhandler> 

in order make i've created default rest service using template provided visual studio here service class :

public class service1     {         // todo: implement collection resource contain sampleitem instances          [webget(uritemplate = "")]                 public list<sampleitem> getcollection()         {             // todo: replace current implementation return collection of sampleitem instances\            // throw new webexception("lala");            throw new webfaultexception<errorhandler>(new errorhandler { cause = "resource not  available", errorcode = 100 }, system.net.httpstatuscode.notfound);             //return new list<sampleitem>() { new sampleitem() { id = 1, stringvalue = "hello" } };         }          [webinvoke(uritemplate = "", method = "post")]         public sampleitem create(sampleitem instance)         {             // todo: add new instance of sampleitem collection                        return new sampleitem() { id = 3, stringvalue = "59" };          }          [webget(uritemplate = "{id}")]         public sampleitem get(string id)         {             // todo: return instance of sampleitem given id             throw new notimplementedexception();         }          [webinvoke(uritemplate = "{id}", method = "put")]         public sampleitem update(string id, sampleitem instance)         {             // todo: update given instance of sampleitem in collection             throw new notimplementedexception();         }          [webinvoke(uritemplate = "{id}", method = "delete")]         public void delete(string id)         {             // todo: remove instance of sampleitem given id collection             throw new notimplementedexception();         }      } } 

as can see code above throwing webfaultexception in getcollection method. should put in body of response "errorhandler" object. here how errorhandler class looks :

using system; using system.collections.generic; using system.linq; using system.web; using system.runtime.serialization;  namespace wcfrestservice1 {     [datacontract]     public class errorhandler     {         [datamember]         public int errorcode { get; set; }         [datamember]         public string cause { get; set; }      } } 

the crazy thing thing works down't :)). i'm trying visual studio giving me error saying webfaultexception not caught user code :| , suspends app. if press continue works should. here pictures describing problem:

first step in fiddler : first step

next visual studio's error: visual studio error

finally after pressing continue works :

it makes no sense me , have no idea why thing happening , how fix :p. i've searched web days trying find solution no luck. i'm using visual studio 2010 ultimate

best regards :)

nothing wrong here. debugging, exception thrown, breaks, continue , works should.

i suspect have set exception handling option (ctrl+alt+e) break when exceptions thrown. ("thrown" in options) cause break whenever exception thrown regardless handled.

exceptions thrown in wcf operations handled wcf runtime , if faults, sent such channel not faulted.

now regard sending xml, can send string representation of xml using webfaultexception<string>.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -