How can I change minOccurs="1" in asp.net 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="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"  xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <s:sequence>
    <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"/>
  </s:sequence>
</s:complexType>

Open in new window

VoodooUKAsked:
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
0
 
Éric MoreauSenior .Net ConsultantCommented:
declare as nullable types
0
 
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
0
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:
0
 
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 :(
0
 
Éric MoreauSenior .Net ConsultantCommented:
have you tried:

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

<s:element minOccurs="1" maxOccurs="1" name="RecordID" nillable="true" type="s:int"/>
0
 
É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.
0
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.