gabitzish
gabitzish

Reputation: 9691

WCF - There was an error downloading

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

Answers (3)

granadaCoder
granadaCoder

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)

http://www.biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalksyn/archive/2008/05/13/datacontracts-without-attributes-poco-support-in-net-3-5-sp1.aspx

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

iamkrillin
iamkrillin

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

Peter
Peter

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

Related Questions