What does adding Name and Namespace to DataContract do?

Viewed 28346

I tried calling a WebInvoke method called Register which returns takes in a User object and immediately just returns that object. It looks like the following:

User Register(User user)
{
    return user;
}

I am not sure what the Name and Namespace attributes do to the DataContract attribute when calling http://localhost:8081/user/register for example?

The reason I ask is because I initially had my class decorated with the DataContract attribute like this:

[DataContract]
public class User
{
   // Properties
}

When I opened up Fiddler, and sent a Post request, it said method not allowed, but when I changed DataContract to:

[DataContract(Name="User", Namespace="")]

It worked.

5 Answers
Related