I have a webservice
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;}
One of my webMethods should return a dynamic object
WebMethod:
Solution 1
[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;
}
Decision 2
[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;
}
Both do not work. Answer: ERR_CONNECTION_RESET
Any ideas how to implement this? Thanks for the help.
source
share