Can I use a Class object as a DataMember?
<p>This is the class need to serialized.</p>

<pre><code>[DataContract]
    public class Fullresponse
    {
        [DataMember(Order=0)]
        public string success { get; set; }
        [DataMember]
        public string participants { get; set; }
        [DataMember]
        public string term { get; set; }
        [DataMember]
        public categoryCollection categories { get; set; }

        [DataMember]
        public string total { get; set; }



    }
</code></pre>

<p>This is categoryCollection Class</p>

<pre><code>[DataContract]
    public class categoryCollection
    {
        [DataMember]
        public Results online { get; set; }
        [DataMember]
        public Results offline { get; set; }
    }
</code></pre>

<p>And this is result class</p>

<pre><code>public class Results
    {
        public string categoryName { get; set; }


        public List&lt;Node&gt; results { get; set; }
    }
</code></pre>

<p>I want to get Fullresponse class object from WCF service to my client app.
How Can I achieve this. From this code it is give an error. When I remove categoryCollection object from Fullresponse class it works fine.</p>

<p>This is my Service web.config</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;configuration&gt;
  &lt;system.diagnostics&gt;
    &lt;sources&gt;
      &lt;source name="System.ServiceModel"
      switchValue="Information, ActivityTracing"
      propagateActivity="true"&gt;
        &lt;listeners&gt;
          &lt;add name="traceListener"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData= "c:\log\TracesTest1.svclog" /&gt;
        &lt;/listeners&gt;
      &lt;/source&gt;
    &lt;/sources&gt;
  &lt;/system.diagnostics&gt;
  &lt;appSettings&gt;
    &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
  &lt;/appSettings&gt;
  &lt;system.web&gt;
    &lt;compilation debug="true" targetFramework="4.5" /&gt;
    &lt;httpRuntime targetFramework="4.5"/&gt;
  &lt;/system.web&gt;
  &lt;system.serviceModel&gt;
    &lt;behaviors&gt;
      &lt;serviceBehaviors&gt;
        &lt;behavior&gt;
          &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
          &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
          &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
          &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
        &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
    &lt;/behaviors&gt;
    &lt;protocolMapping&gt;
        &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
    &lt;/protocolMapping&gt;    
    &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
  &lt;/system.serviceModel&gt;
  &lt;system.webServer&gt;
    &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      --&gt;
    &lt;directoryBrowse enabled="true"/&gt;
  &lt;/system.webServer&gt;

&lt;/configuration&gt;
</code></pre>

<p>And This is my Client app.config</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
    &lt;startup&gt; 
        &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;system.serviceModel&gt;
        &lt;bindings&gt;
            &lt;basicHttpBinding&gt;
                &lt;binding name="BasicHttpBinding_IService1" /&gt;
            &lt;/basicHttpBinding&gt;
        &lt;/bindings&gt;
        &lt;client&gt;
            &lt;endpoint address="http://localhost:23894/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" /&gt;
        &lt;/client&gt;
    &lt;/system.serviceModel&gt;
&lt;/configuration&gt;
</code></pre>

<p>stack trace of error..</p>

<blockquote>
  <p>System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String
  message, HttpStatusCode statusCode, String statusDescription)
  System.ServiceModel.Channels.HttpInput.ValidateContentType()
  System.ServiceModel.Channels.HttpInput.ParseMessageAsyncResult.BeginParse()
  System.ServiceModel.Channels.HttpInput.BeginParseIncomingMessage(HttpRequestMessage
  httpRequestMessage, AsyncCallback callback, Object state)
  System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginParseIncomingMessage(AsyncCallback
  asynCallback, Object state)
  System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult..ctor(ReplyChannelAcceptor
  acceptor, Action dequeuedCallback, HttpPipeline pipeline,
  AsyncCallback callback, Object state)
  System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor
  replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback,
  Object state)
  System.ServiceModel.Channels.HttpChannelListener<code>1.HttpContextReceivedAsyncResult</code>1.ProcessHttpContextAsync()
  System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext
  context, Action acceptorCallback, AsyncCallback callback, Object
  state)
  System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult
  result)
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object
  state)
  System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback
  callback, Object state)
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object
  state)
  System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32
  errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
  System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32
  error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
  System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
  errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</p>
</blockquote>

<p>Client Side Code </p>

<pre><code>private void button1_Click(object sender, EventArgs e)
        {
            Service1Client clirnt = new Service1Client();
            Fullresponse C = new Fullresponse();
            C = clirnt.GetDataUsingDataContractnew("","");


        }
</code></pre>

<p>IService.cs</p>

<pre><code>[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(int id);

        [OperationContract]
        Fullresponse GetDataUsingDataContractnew(string id, string skey);
        // TODO: Add your service operations here
    }
</code></pre>

<p>Service1.svc.cs</p>

<pre><code>  public class Service1 : IService1
     {
         public string GetData(int value)
         {
             return string.Format("You entered: {0}", value);
         }

         public CompositeType GetDataUsingDataContract(int id)
         {
             CompositeType ct = new CompositeType();
             return ct;
         }

         public Fullresponse GetDataUsingDataContractnew(string id,string skey)
         {
             Fullresponse fr = new Fullresponse();
             SearchContacts sr = new SearchContacts();
             fr = sr.GetJson(id, skey);
             return fr;
         }
     }

getJson method

     public Fullresponse GetJson(string id, string skey)
            {
                List&lt;Node&gt; on = new List&lt;Node&gt;();
                List&lt;Node&gt; off = new List&lt;Node&gt;();
                Results Online = new Results();
                Results Offline = new Results();

                on.Add(new Contact("on1", "url1", "des1", "aaa"));
                off.Add(new Contact("off2", "url2", "des2", "bbb"));
                Online.categoryName = "Online";
                Online.results = on;
                Offline.categoryName = "Offline";
                Offline.results = off;
                categoryCollection categoryCollection = new categoryCollection();
                categoryCollection.online = Online;
                categoryCollection.offline = Offline;

                Fullresponse searchCon = new Fullresponse();
                searchCon.success = "true";
                searchCon.term = "a";
                searchCon.categories = categoryCollection;
                searchCon.total = "1";

                return searchCon;

            }
</code></pre>

<p>Node Class</p>

<pre><code> [DataContract]
    public abstract class Node
    {
        [DataMember]
        public string title { get; set; }
        [DataMember]
        public string name { get; set; }
        [DataMember]
        public string url { get; set; }

        [DataMember]
        public string description { get; set; }

       [DataMember]
        public List&lt;Action&gt; actions { get; set; }
        public virtual void AddComment()
        {

        }
        public virtual void AddContact()
        {

        }
    }
</code></pre>

<p>Action Class</p>

<pre><code> [DataContract]
    public class Action
    {
        public Action() { }
        public Action(string icon, string url)
        {
            this.icon = icon;
            this.url = url;
        }
        [DataMember]
        public string icon { get; set; }
        [DataMember]
        public string url { get; set; }
    }
</code></pre>

<p>Please Help me to solve this.</p>