我有一个简单的实体,它的属性之一是必需的:
[DataContract]
public class Person
{
[DataMember]
public string FirstName { get; set; }
[DataMember (IsRequired=true)]
public string LastName { get; set; }
}
这是服务的接口:
[ServiceContract]
public interface IService1
{
[OperationContract]
Person DoubleLastName(Person person);
}
这是服务:
public class Service1 : IService1
{
public Person DoubleLastName (Person person)
{
return new Person { FirstName = person.LastName, LastName =
person.LastName};
}
}
这就是问题所在:当客户端向该服务发送对象时, 没有所需的属性,一切正常。我不应该得到一个例外吗?
using (Service1Client myProxy = new Service1Client())
{
Person person1 = new Person { }; //Here I don't notify the required value.
Person person = myProxy.DoubleLastName(person1);
}