propagate an exception of a concrete type in Indigo

Hello everyone from Spain,

I am trying to propagate an exception, whose type is ExcepcionConcurrencia (it is Spanish). Well, the issue is that it doesn't propagate the exception of the type that I have defined, it propagates ServiceModel.FaultException. I need my type because I propagate a DataSet in it.

I have tried using the ServiceKnownType Tag but it doesn't work.

How could I achieve it

Thanks in regards




Answer this question

propagate an exception of a concrete type in Indigo

  • Thomas LEBRUN

    Hi,

    You need to annotate your ServiceOperation with a FaultContract. Here are the steps:

    By the way, OperationContract's have to be two-way for SOAP fault to be returned.

    //1.Define a DataContract for your error type

    [DataContract]

    public class MyError

    {

    [DataMember]

    public DataSet ErrorDS;

    }

    //2.Annotate your Operation with a FaultContract

    [ServiceContract]

    public interface IMyService

    {

    [OperationContract]

    [FaultContract(typeof(MyError))]

    int MyOperation(int id);

    }

    //3. In the service implementation when exceptions occur throw a FaultException<MyError>

    MyError me = new MyError();

    me.ErrorDS = ...

    FaultException<MyError> fe = new FaultException<MyError>(me, new FaultReason("Validation failed"));

    throw fe;

    //4. Catch the exception in the cient

    try

    {

    ......

    }

    catch (FaultException<MyError> me)

    {

    String message = String.Format("{0}. No. of Error rows = {1}", me.Message, me.Detail.ErrorDS.Tables[0].Rows.Count);

    MessageBox.Show(message);

    }

    Hth.



  • Frank Uray

    I love you :)



  • johnny_no1_boy

    ups, i can not get it working. I have done all what you say, but it gives me that excepcion, i am trying to find in google but I haven't found any solution. I have tested debugging and with release with the same error. Perhaps i have to write something in the config. Do you know any solution

    Thanks

    The exception:

    An error occurred while receiving the HTTP response to http://localhost:8080/ServidorSiliis/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.



  • Bob Pokorny

    Hope your are using the same binding type on both Server and client.

    I would suggest that you try hosting the service in WinForns and see if you can get exceptions working and then host in IIS.

    Also, you could stubb out a simple method and without any implementation throw your custom FaultException<> and see if you can catch it on the client.



  • ahmedilyas

    Thank You :-) Iam very glad that i can help.

  • propagate an exception of a concrete type in Indigo