Sole552810

I'm doing a simple wcf application. In it I defined a DataContract:

Code Snippet

[DataContract]

public class UsuarioContrasenaIncorrectaFault

{

[DataMember]

public string Message;

public FaultReason Reason = new FaultReason("Ingreso incorrectamente el usuario o la contrasena");

}

and an a service operation that throws two FaultException to the client:

Code Snippet

[OperationContract]

[FaultContract(typeof(UsuarioContrase aIncorrectaFault))]

[FaultContract(typeof(FueraDeTurnoFault))]

public bool Login(string , string)

{

try

{

...

}

catch (Exception ex)

{

UsuarioContrase aIncorrectaFault fault = new UsuarioContrase aIncorrectaFault();

fault.Message = ex.Message;

throw new FaultException<UsuarioContrase aIncorrectaFault>(fault, fault.Reason);

}

return false;

}

But everytime it get to the line that throws the FaultException I get this error:

System.ServiceModel.FaultException`1 was unhandled by user code

And still the client can catch the FaultException correctly

catch (FaultException<ClientePrueba.IrisRemoteService.UsuarioContrasenaIncorrectaFault> ex)

{

response = ex.Reason.ToString() ;

}

I've read a lot but I can't find a solution. I would appreciate any help.

Thanks!




Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

Mark A. Richman

Try applying [DataMember] to Reason.



Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

Brian McNamara - MSFT

I am unclear what the problem/question is. It looks like your server code is good, and I think from your description it sounds like the client is able to catch the FaultException when it is thrown on the server. Is that correct I am unclear when the 'unhandled by user code' is happening, and where (presumably on the client, when you don't have the 'catch' block )...




Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

Sole

Thanks for your replies.

It didn't work applying [DataMember] to Reason.

The exception is thrown in the server, inmediatly after the

throw new FaultException<UsuarioContrase aIncorrectaFault>(fault, fault.Reason);

and the execution of the service stops to show
System.ServiceModel.FaultException`1 was unhandled by user code .

But if a press continue after that, the client can catch the FaultException correctly.

The problem is that the execution in the server stops, and I don't understant why. It seems like the server needs to handle the same exception that is throwing.

I hope is it clear enough. I'm sorry if is not.






Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

Brian McNamara - MSFT

I think what you are describing is merely a feature of the Visual Studio debugger. It sounds like you have the 'catch all first chance exceptions' checkbox enabled somewhere, and so the debugger is dutifully pausing each time an exception is thrown. Furthermore, it sounds like the 'enable debugging assistant' and 'just my code' options are also checked; these options in my opinion just make the VS messages more annoying and incomprehensible, so consider unchecking them.

In short, I think your service and client are working just fine.






Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

fatma

hii

i have the same problem...i am throwing an Customdefined exception (lets say "throw new fatmaException") but i get the same error. what have you done to solve this problem





Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

Sole

I unchecked the options that Brian suggested and the problem dissapeared.






Re: Windows Communication Foundation (Indigo) Problem throwing a FaultException<T>

S_Venter

I had a similar problem in Visual Studio 2008. Unchecking the option under Tools->Options->Debugging->General->Enable Just My Code seems to solve the problem.