c# - throwing exception from WCF -




I'm trying to throw an exception from the WCF module to client modules. I am getting the following error "User forgot fault problem"

In the service side

  Public IList & lt; UserEntity & gt; SearchUserDetail (string username) {try {int y = 0; Int u = 9 / y; New UserViewModel () Return. SearchUserDetail (userName); } Hold (Exception preceding) {New fault fault (new fault region (ex.Message), New FaultCode ("Data Access Error")); }}   

On Customer Side

  Try ServiceReference.ServiceClient servRef = new ServiceReference.ServiceClient (); & Lt; UserEntity & gt; User = new list & lt; UserEntity & gt; (); Users.AddRange (servRef.SearchUserDetail ("Jacson")); DataGridView1.DataSource = Users; } Hold (System.ServiceModel.FaultException exc) {logging.log (new exception ("search user", exc)); }   

I have added the following attribute in the service module's app.config

  in the service debug included ExceptionDetailInFaults = "True"   

Any solutions know?

You must add FaultContractAttribute to the method SearchUserDetail , if it contains the Operation Contract attribute And your service is part of the contract class. [ServiceContract] Interface IMyServiceContract {[Operation Contract] [FaultContract (typeof (...)] IList & lt; UserEntity & gt; SearchUserDetail (String Username)}

I'm not sure about the type of FaultContract, but take a look at msdn.

Comments