When using a data entity / model class that is defined by a Web Service Reference, you cannot add DataAnnotations attributes to it directly. (The code is in a generated References.cs file that gets overwritten when you update the service reference.) The generated web service entity class uses partial, which allows you to specify a separate class for the attributes.

In this example, ContactsEntity is a generated class from the ContactsService service reference. We add [MetadataType] to specify where the attributes can be found. Nothing else needs to be modified (though, if you need to, you can add additional properties here for use in your views and controllers.)

Note that this class must be in the same namespace as the generated class.

namespace MVC.SurroundTechWebsite.ContactsService
{
    [MetadataType(typeof(ContactsEntityMetadata))]
    public partial class ContactsEntity
    {
    }
}

To add attributes, implement the metadata class with fields whose names and types match the entity class' properties, and then add attributes to those fields. This class can be in the same namespace, but that's not required.

public class ContactsEntityMetadata
{
    [Required(AllowEmptyStrings = false, ErrorMessage = "Required")]
    public string FirstName;

    [Required(AllowEmptyStrings = false, ErrorMessage = "Required")]
    public string LastName;

    [Required(AllowEmptyStrings = false, ErrorMessage = "Required")]
    public string CompanyName;

    [Required(AllowEmptyStrings = false, ErrorMessage = "Required")]
    [DataType(DataType.PhoneNumber)]
    public string PhoneNumber;

    [Required(AllowEmptyStrings = false, ErrorMessage = "Required")]
    [DataType(DataType.EmailAddress)]
    public string Email;

    [DataType(DataType.Url)]
    public string Website;

    [DataType(DataType.MultilineText)]
    public string AdditionalComments;
}