views:

4691

answers:

2

I'm writing a simple web service using Microsoft Visual Web Developer 2005 (Express Edition), and the dynamically generated WSDL has a minOccurs="0" for all the parameters.

How do I get minOccurs="1" for the required parameters without resorting to creating a static WSDL file?

I need to do this using a ASP.NET Web Service (.NET v2). So, no WCF.

A: 

from an msdn forum "If you are creating a new web service, I highly recommend building the web service using the Windows Communication Foundation (WCF) instead of using ASP.NET Web Services. In WCF, when you specify the data contract for your service you can speicfy that a given data member is required using the IsRequired property on the DataMemberAttribute. "

source - http://social.msdn.microsoft.com/forums/en-US/asmxandxml/thread/40ab5748-d32c-42a6-a47f-984ba18a1fe2/

Jack B Nimble
+1  A: 

I think that the XmlElement(IsNullable = true) attribute will do the job:

using System.Xml.Serialization;

[WebMethod]
public string MyService([XmlElement(IsNullable = true)] string arg)
{
  return "1";
}
Panos