Pregunta

i'm trying to use a WCF Plain service with Telerik OpenAccess in VS 2012 with .net 4.5.

I tried the telerik developers manual and created the service and a client.

In the service interface IEntitiesModel I put

[OperationContract]
[FaultContract(typeof(string))]
PersistentDto ReadPersistentDto(string dtoKey);

In the EntitiesModel.SVC for the method I used an easy construct as first try:

public PersistentDto ReadPersistentDto(string dtoKey)
{
   throw new FaultException("test");
} 

In user code of Consumer i put a catch for the exception.

Now the problem is:

Every time the service is called, Visual Studio stops in "throw new FaultException" with the error message, that FaultException was not handled by usercode. If i continue with F5, the exception is also caught by usercode of consumer.

Why does it stop in the service?

In my understanding a FaultException is something which should be passed to the consumer of a service.

What should i do to throw a FaultException correctly?

¿Fue útil?

Solución

Go to Debug -> Exceptions and uncheck the checkbox under Thrown column for row CLR exception.

If that checkbox is checked, it will cause the debugger to stop at every location where you are throwing exception.

Otros consejos

This is related to setting. You can do required setting by going to Tools-> options Now switch to debugging menu and uncheck
"Enable the exception assistant" and
"Enable just my code" enter image description here

The server does not know that the client will handle the exception (how should he?). This is why the debugger tells you that it is unhandled.

You have also throw the fault like this:

public PersistentDto ReadPersistentDto(string dtoKey)
{
   throw new FaultException<string>("test");
} 

This matches your declaration:

[FaultContract(typeof(string))]

It's related with debbugging. However it won't stop your service while executing (unless you don't manage the exception properly).

As RV1987 said, if VS has CLR Exceptions enabled, it will let you know anytime an exception has been thrown.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top