2017-08-31 34 views
0

我正在创建SOAP Web服务。我请求XML是这样的:XML asmx注释未验证大小和要求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> 
    <soapenv:Body> 
     <tem:Inserir> 
     <tem:dados> 
      <tem:NroEmpresa>aaaa</tem:NroEmpresa> 
      <tem:NomeCliente>dfdsfdsfsdfdsfdsfd</tem:NomeCliente> 
     </tem:dados> 
     </tem:Inserir> 
    </soapenv:Body> 
</soapenv:Envelope> 

我的XML对象是这样的:

public class NoContaDigital 
{ 
    [XmlElement(IsNullable = false)] 
    [StringLength(2,ErrorMessage="Tamanho do campo excede limite."),Required] 
    public string NroEmpresa { get; set; } 
    [XmlElement(Type = typeof(string),IsNullable =false)] 
    [StringLength(80, ErrorMessage = "Tamanho do campo excede limite."), Required] 
} 

与2极限StringLength没有被验证甚至没有,如果我发送一个空值(需要it's )。

我是否需要实现任何类来验证它?

回答

1

也许你可以试试:

public class NoContaDigital 
{ 
    [XmlElement(IsNullable = false)] 
    [Required(ErrorMessage = "Required")] 
    [StringLength(2,ErrorMessage="Tamanho do campo excede limite.")] 
    public string NroEmpresa { get; set; } 
} 

这可能是数据标注的顺序。