I am using the following method to send a JSON representation of a List of a custom object through a WCF service hosted on my local machine:
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
public List<MyObject> GetObjects()
{
return MyObject.GetObjects();
}
The class MyObject is marked with the [DataContract] attribute, When I request the method using Rest URL, I get the error
This webpage is not available, The connection to localhost was interrupted.
When I remove the [DataContract] atribute, it works fine. I read many articles that you should enable SSL and configure the service behavior to set the certificate name and store and that sort of stuff, but isthis the right and only way to make it work? Shouldn’t it be straighforward?
The code for MyObject is :
[DataContract]
public class MyObject
{
[DataMember]
public int ID { get ; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
}
Make sure that all the properties marked as [DataMember] have get and set, that is they are not readonly, not sure why but I once faced this issus and solved it like this.