Question : Sending objects containing objects from WCF Server


Hello,
I have a WCF Server that returns a ResponseType class object that i have created. The class is shown in the code section.

When the WCF Client  invokes a WCF Server Function and the   server operation is a success
(for example  WCF server succesfully connects to the database)  ResponseObj will be  some
string data. In this scenario everything is working fine. (r_type.ResponseObj="Connection is OK")

But  when   a exception occurs at the WCF server  i catch that exception and want to inform the client about the exception. And i want to directly send the exception object to the WCF client. So i use something like this:
catch(Exception ex)
{
r_type.Responsebj=ex;
return r_type;
}

But  at the WCF client i get the exception : Server is in the faulted state.

In short  when the object type ResponseType is a complex object like Exception class object
instead of int or string, the system does not work.
Is there a workaround to overcome this issue ?

Note : If i add  another DataMember  like Exception ex to the ResponseType Class then i can
succesfully send the exception to the client. But I do not want to add a DataMember  for
each type of exception. By using reflection at the client (.GetType())  i can already understand
the type of the object.

I am sorry and i hope i have made myself clear.
thanks





Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
[DataContract]
 public class ResponseType
    {
        private object responseObj;    
        private string additionalData;

        [DataMember]
        public object ResponseObj
        {
            get { return responseObj; }
            set { responseObj = value; }
        }
        [DataMember]
        public string AdditionalData
        {
            get { return additionalData; }
            set { additionalData = value; }
        }
}

Answer : Sending objects containing objects from WCF Server

u need to modify your web.config:




 
   
   

     

       

              ults="true" /> -->THIS ONE !!!!

       


     


   


 

Random Solutions  
 
programming4us programming4us