svcutil.exe datacontract only is not generating minOccus='1'

Call "C:\Program Files\Microsoft SDKs\Windows\v1.0\Bin\svcutil.exe" /dconly /out:..\..\DataContractXSD.cs /t:code "$(ProjectDir)Data.xsd"

Data.xsd file has

<xsd:complexType name="AccessInfo">

<xsd:sequence>

<xsd:element name="User" type="xsd:string" minOccurs="1" maxOccurs="1"/>

<xsd:element name="Password" type="xsd:string" minOccurs="1" maxOccurs="1"/>

<xsd:element name="ApplicationID" type="xsd:string" minOccurs="1" maxOccurs="1"/>

<xsd:element name="ClientIPAddress" type="xsd:string" minOccurs="1" maxOccurs="1"/>

</xsd:sequence>

</xsd:complexType>

but svcutil creates it with out the correct minOccurs values...

-<xs:complexType name="AccessInfo">
-<xs:sequence>
<xs:elementminOccurs="0" maxOccurs="1" name="ExtensionData" type="tns:ExtensionDataObject" />
<xs:elementminOccurs="0" maxOccurs="1" name="User" type="xs:string" />
<xs:elementminOccurs="0" maxOccurs="1" name="Password" type="xs:string" />
<xs:elementminOccurs="0" maxOccurs="1" name="ApplicationID" type="xs:string" />
<xs:elementminOccurs="0" maxOccurs="1" name="ClientIPAddress" type="xs:string" />
</xs:sequence>
</xs:complexType>

Also does anyone know how to suppress the ExtensionData so it is not created in the generated class?

Thanks for any help or info.

[8414 byte] By [ACHawk] at [2007-12-24]
# 1

So no one at MS can answer this question?

Thanks for any help.

ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2

no one at MS can answer this question?

Thanks for any info.

ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3
no one at MS can answer this question?
ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4
did not mean to post three times.. this system said there was an error, so I posted again to get past the error. oops.
ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5

i think by default,Datacontract members are optional(soap message may or may not have all the data members),so minoccures=0 make sense for me.

if you want force soap message to have all data contract members,you can use isrequired option

[DataContract]

publicclassEmployee

{

[DataMember(IsRequired=true)]

string Name;

[DataMember]

int Age;

}

MadhuPonduru-MSFT at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 6

looks like svcutil generated class is creating the IsRequired=true, but the XSD generated at runtime does not.

So this is a bug with the runtime XSD generation....

- Runtime XSD.
<xs:complexType name="AccessInfo">
-<xs:sequence>
<xs:elementminOccurs="0" maxOccurs="1" name="ExtensionData" type="tns:ExtensionDataObject" />
<xs:elementminOccurs="0" maxOccurs="1" name="User" type="xs:string" />
<xs:elementminOccurs="0" maxOccurs="1" name="Password" type="xs:string" />
<xs:elementminOccurs="0" maxOccurs="1" name="ApplicationID" type="xs:string" />
<xs:elementminOccurs="0" maxOccurs="1" name="ClientIPAddress" type="xs:string" />
</xs:sequence>
</xs:complexType>
Class Generated by svcutil:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]

[System.Runtime.Serialization.DataContractAttribute()]

publicpartialclassAccessInfo : object, System.Runtime.Serialization.IExtensibleDataObject

{

private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

privatestring UserField;

privatestring PasswordField;

privatestring ApplicationIDField;

privatestring ClientIPAddressField;

public System.Runtime.Serialization.ExtensionDataObject ExtensionData

{

get

{

returnthis.extensionDataField;

}

set

{

this.extensionDataField = value;

}

}

[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]

publicstring User

{

get

{

returnthis.UserField;

}

set

{

this.UserField = value;

}

}

[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, Order=1)]

publicstring Password

{

get

{

returnthis.PasswordField;

}

set

{

this.PasswordField = value;

}

}

[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, Order=2)]

publicstring ApplicationID

{

get

{

returnthis.ApplicationIDField;

}

set

{

this.ApplicationIDField = value;

}

}

[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true, Order=3)]

publicstring ClientIPAddress

{

get

{

returnthis.ClientIPAddressField;

}

set

{

this.ClientIPAddressField = value;

}

}

}

ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 7
The ExtensionData is actually a feature that must be built into the type for round-tripping. Essentially, round-tripping is a mechanism that allows your type to be versioned properly. It ensures that no data is lost in later versions of this DataContract. As a best practice, I highly recommend leaving the ExtensionData that is generated.
DaveCliffe-MSFT at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 8

Thanks for the ExtensionData answer.

The main question was why the minOccurs is not working correctly when the XSD is generated at runtime

minOccurs is set to "0" when it should generate minOccurs="1" because of the IsRequired=true attribute.

Class

[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]

public string User

Runtime XSD.

<xs:element minOccurs="0" maxOccurs="1" name="User" type="xs:string" />

This must be a bug,

MS lets correct it before we go from RC1 to RTM.

ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 9

you are right,for some reason wsdl don't have minoccurs(if isrequired=true),so my guess is,svcutil treating(if no minoccurs, minoccurs=1),xsd may be treating(if no minoccurs, minOccurs=0)

i am checking with svcutil team to know why we are not adding minoccurs in wsdl(if isrequired=true),I will update you on this asap.

-Thank you

Madhu

MadhuPonduru-MSFT at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 10
How are you generating the "runtime schema"? You are not using the xsd.exe or wsdl.exe tools, are you? It looks like the XmlSerializer is being used instead of the DataContractSerializer. This is why you see all that "extension data" stuff in the schema (it should never show up there), and this is why minOccurs=0 (the XmlSerializer does not understand the DataMemberAttribute and its IsRequired property). Make sure you're using the correct serializer.
EugeneOsovetsky at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 11

I am using svcutil.exe like I should.

Call "C:\Program Files\Microsoft SDKs\Windows\v1.0\Bin\svcutil.exe" /dconly /out:..\..\DataContractXSD.cs /t:code "$(ProjectDir)Data.xsd"

It svcutil.exe creates the class correctly; it is at run time when you retrieve the wsdl/xsd contract info the Min Occurs gets generated incorrectly.

ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 12

Madhu wrote: wsdl don't have minoccurs(if isrequired=true),so my guess is,svcutil treating(if no minoccurs, minoccurs=1)...

That's interesting. In regards to my post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=713059&SiteID=1&mode=1, I guess the problem really is that the WSDL has minoccurs=0 by default. I wish the default was 1 and of course the method should not get executed when the minoccurs requirement is not satisfied.

Manish3177 at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 13

Hi Madhu,

any info from the svcutil team?

I hope we can fix this before the RTM release.

ACHawk at 2007-10-7 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified