Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1716
  • Last Modified:

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

0
VoodooUK
Asked:
VoodooUK
  • 4
  • 4
5 Solutions
 
É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
 
Éric MoreauSenior .Net ConsultantCommented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now