Reputation: 9691
I have a test class that I'm using trying to make a WCF service, the class looks like this:
public class TestObject
{
public int ObjID { get; set; }
public string ObjName { get; set; }
public TestObject(int id, string name) {
ObjID = id;
ObjName = name;
}
}
When I try to import the service reference into a clien app, I get this error There was an error downloading [...]
. If I add [DataContract]
and [DataMember]
tags to my class, it works just fine, however, I would like to use it without adding DataContract.
Any idea about solving this issue?
Upvotes: 0
Views: 128
Reputation: 27884
[Serializable]
Try that attribute on the class .. as a first attempt.
See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx
Here is the article I was looking for (or one like the one I remember)
Things changed with Framework 3.5 SP1.
So, the answer is "Yes you can".. "but it depends on the Framework Version" and it depends on the Serialize (DataContractSerializer).
Upvotes: 0
Reputation: 6876
It is possible to use wcf object without specifiing the [DataContract]
or [DataMember]
attribute, but in order for that to work you need to also include an empty contructor. This constructor does not have to be public as in the example below, but you do have to have one (public, private, internal, etc)
public class TestObject
{
public int ObjID { get; set; }
public string ObjName { get; set; }
public TestObject()
{
}
public TestObject(int id, string name)
{
ObjID = id;
ObjName = name;
}
}
Upvotes: 1
Reputation: 27944
You resolve the issue by adding [DataContract] and [DataMember]. WCF needs these tags for serialization of your data objects. Without them, the object or field will not be serialized or included in the contract.
Upvotes: 0