views:

129

answers:

0

Is there an easy way to force the WebService .Net XmlSerialiser to check that an attribute is present?

In the following example, I want the webService's caller do not forget to set the Price and the Currency:

public class Quote
{
   public decimal Price;
   public string Currency;
}

[WebService]
public class MyWebService : WebService
{
   [WebMethod()]
   public void Save(Quote quote)
   {
       if(quote == null)
       {
          throw new ArgumentNullException("Quote");
       }
       if(quote.Price == 0m)
       {
          throw new ArgumentNullException("quote.Price");
       }
       if(quote.Currency == null)
       {
          throw new ArgumentNullException("quote.Currency");
       }
       ///Do real job here
   }
}

Is exists a XmlElmentAttribute option that can allow me to avoid the 'if(x == null) throw new Exception()' part? Does it exists an easier way to do?