WCF exception exception



I am trying to pass an exception from a WCF module to a client module. I get the following error: "FaultException was unhandled by the user"

on the part of the service

public IList<UserEntity> SearchUserDetail(string userName) { try { int y = 0; int u = 9 / y; return new UserViewModel().SearchUserDetail(userName); } catch (Exception ex) { throw new FaultException( new FaultReason(ex.Message),new FaultCode("Data Access Error")); } } 

on the client side

 try { ServiceReference.ServiceClient servRef = new ServiceReference.ServiceClient(); List<UserEntity> users = new List<UserEntity>(); users.AddRange(servRef.SearchUserDetail("Jacson")); dataGridView1.DataSource = users; } catch (System.ServiceModel.FaultException exc) { Logging.Log(new Exception("Search User", exc)); } 

In the app.config of the service module, I added the following attribute

  serviceDebug includeExceptionDetailInFaults="True" 

Does anyone know a solution?

+4
source share
3 answers

You must add a FaultContractAttribute to the SearchUserDetail method if it has an OperationContractAttribute and is part of your ServiceContract class.

 [ServiceContract] interface IMyServiceContract { [OperationContract] [FaultContract(typeof(...)] IList<UserEntity> SearchUserDetail(string userName) } 

I am not sure about the type of FaultContract. But look at msdn.

+4
source

I know that I am late here, but just in case someone came across this, I had the same error, and everything was in order in my code.

It turns out that this only happened in Visual Studio because of some debugging options. See here for an explanation.

+1
source

Source: https://habr.com/ru/post/1344061/


All Articles