How can I change minOccurs="1" in to 0?

I have a a User Class which defines various properties and its also used to pass as a webservice object. Asp.Net adds minOccurs=1 for all integers / date objects etc.

I want to change the minOccurs fro all the integers to 0

How can I do this?
public class User
	public User()
    // Non null values
    //@todo: These should throw null argument exception
    public string Firstname { get; set; }
    public string Surname { get; set; }
    public string Gender { get; set; }
    public DateTime Date_of_birth { get; set; }
    // These can have null values
    public int RecordID { get; set; }
    public int EventID { get; set; }
    public string UserID { get; set; }
    public string Title { get; set; }
    public string Email { get; set; }
    public string Address1 { get; set; }
// Here is the XML
<s:complexType name="User" xmlns:soap="" xmlns:tm="" xmlns:soapenc="" xmlns:mime=""  xmlns:s="" xmlns:soap12="" xmlns:http="" xmlns:wsdl="">
    <s:element minOccurs="0" maxOccurs="1" name="Firstname" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="Surname" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="Gender" type="s:string"/>
    <s:element minOccurs="1" maxOccurs="1" name="Date_of_birth" type="s:dateTime"/>
    <s:element minOccurs="1" maxOccurs="1" name="RecordID" type="s:int"/>
    <s:element minOccurs="1" maxOccurs="1" name="EventID" type="s:int"/>
    <s:element minOccurs="0" maxOccurs="1" name="UserID" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="Title" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="Email" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="Address1" type="s:string"/>

Open in new window

Who is Participating?
VoodooUKAuthor Commented:
Thanks anyway,
It will also depend on how the client reads it... I am reading it in a Flex client which looks for both minOccurs and nullable...

I will have to do a work around in that I will have to declare the same User class in Flex so that the parameters like int are 0 instead of Null
Éric MoreauSenior .Net ConsultantCommented:
declare as nullable types
VoodooUKAuthor Commented:
Thanks for the reply!

Declaring as Nullable results in the follwing:
<s:element minOccurs="1" maxOccurs="1" name="RecordID" nillable="true" type="s:int"/>

minOccurs is still 1
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Éric MoreauSenior .Net ConsultantCommented:
VoodooUKAuthor Commented:
Yep, thats exactly what I did:

public System.Nullable<int> RecordID { get; set; }

which is same as you suggested. But it does not change minOccurs :(
Éric MoreauSenior .Net ConsultantCommented:
have you tried:

public int? RecordID { get; set; }
VoodooUKAuthor Commented:
Yeah, same result:

<s:element minOccurs="1" maxOccurs="1" name="RecordID" nillable="true" type="s:int"/>
Éric MoreauSenior .Net ConsultantCommented:
then I don't know.

I had problems with a class like this in a webservice (used from InfoPath) and I solved it using a nullable type.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.