title: C# Rest API return dynamic object
body: <p>I have an webservice </p>
  
  <pre><code>WebServiceHost webServiceHost= new WebServiceHost(typeof(WebMethods), new Uri(url));
  webServiceHost.Open();
  
  public class Fish { public string name = "I am a fish"; }
  public class Dog { public int legs = 4; }
  public class Cat { public DateTime dt = DateTime.Now;}
  </code></pre>
  
  <p>One of my webMethods should return a dynamic object</p>
  
  <p>WebMethod:</p>
  
  <p>Solution 1</p>
  
  <pre><code>[OperationBehavior]
  [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/isTest?class={cl}")]
  object isTest(string cl)
  {
      object obj;
  
      switch (cl)
      {
          case "fish":
              obj= new Fish();
              break;
          case "dog":
              obj= new Dog();
              break;
          default:
              obj= new Cat();
              break;
  
      }
      return obj;
  
  }
  </code></pre>
  
  <p>Solution 2</p>
  
  <pre><code>[OperationBehavior]
  [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/isTest?class={cl}")]
  dynamic isTest(string cl)
  {
      dynamic obj;
  
      switch (cl)
      {
          case "fish":
              obj= new Fish();
              break;
          case "dog":
              obj= new Dog();
              break;
          default:
              obj= new Cat();
              break;
  
      }
      return obj;
  }
  </code></pre>
  
  <p>Both are not working. The response is ERR_CONNECTION_RESET</p>
  
  <p>Any idea how to realise it?
  Thanks for help. </p>