WCF Data Service Error Handling -


i have created wcf data service service operation.

i want generate kind of business exception. try generate webfaultexception don't see how catch error @ client side when error throwing service operation.

here service operation simulate exception:

[webget]  public void generateexception()  {     throw new dataserviceexception( 403, "custom message" ); } 

here client:

webclient wc = new webclient();  wc.downloadstring(     new uri(       "http://localhost:27820/wcfdataservice1.svc/generateexception"     ) ); 

downloadstring throwing exception, it's internal server error, can't see custom message.

any idea ?

many thanks.

it best throw dataserviceexception. wcf data service runtime knows how map properties http response , wrap in targetinvocationexception.

you can unpack client consumer overriding handleexception in dataservice so:

    /// <summary>     /// unpack exceptions consumer     /// </summary>     /// <param name="args"></param>     protected override void handleexception(handleexceptionargs args)     {         if ((args.exception targetinvocationexception) && args.exception.innerexception != null)         {             if (args.exception.innerexception dataserviceexception)                 args.exception = args.exception.innerexception dataserviceexception;             else                 args.exception = new dataserviceexception(400, args.exception.innerexception.message);         }     } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -