rsantos

Hi there,
I have this xsd:

< xml version="1.0" encoding="ISO-8859-1" >
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:my="http://www.localhost.pt/MySchema" elementFormDefault="qualified" targetNamespace="http://www.localhost.pt/MySchema">

<element name="reply" type="my:TypeReply" />
<complexType name="replyType">
<sequence>
<element name="version" type="string" />
<element name="type" type="string" />
<element name="form" type="string" />
</sequence>
</complexType>

<complexType name="TypeReply">
<sequence>
<element name="id" type="string" minOccurs="1"/>
<element name="reply" type="my:replyType" minOccurs="1" maxOccurs="500" />
</sequence>
</complexType>
</schema>

I'm trying to generate the DataContract with SvcUtil.exe like this:

svcutil.exe my.xsd /dataContractOnly /serializer: DataContractSerializer /language:C# /out:MyDataContract.cs

But i'm having this error:

"Error: Type 'TypeReply' in namespace 'http://www.localhost.pt/MySchema' cannot be imported. 'maxOccurs' on element 'reply' must be 1. Either change schema so that the types can map to data contract types or use ImportXmlType or use a different serializer."

There is any chance that i could generate the DataContract with scvutil having elements with maxOccurs > 1

Note:
I really want to use the DataContractSerializer.
If i take out the maxOccurs the svcutil works just fine.




Re: Windows Communication Foundation (Indigo) Problem with xsd element with maxOccurs > 1 when generating the DataContract using svcutil.exe

Allan-Nielsen

rsantos wrote:
Hi there,
There is any chance that i could generate the DataContract with scvutil having elements with maxOccurs > 1

Note:
I really want to use the DataContractSerializer.
If i take out the maxOccurs the svcutil works just fine.

hi,

you need to use the ArrayOf naming convention, you can read about it here and here

I am not very pleased with this convention either

hth, Allan





Re: Windows Communication Foundation (Indigo) Problem with xsd element with maxOccurs > 1 when generating the DataContract using svcutil.exe

rsantos

Hi Allan, thanks for your reply,
It's funny, i read your post from yesterday (in your blog),i try to reply in your blog, but give me some error so i try to check what the wcf team say about this, and here you are Smile.

Anyway i will watch closely to your post .

I will not mark this post already responded to check if the wcf team have another response....




Re: Windows Communication Foundation (Indigo) Problem with xsd element with maxOccurs > 1 when generating the DataContract using svcutil.exe

Allan-Nielsen

Open letter to the WCF team:

Dear WCF team, we are now 2 developers who is not satisfied with this naming convention, that should tell you something ,

please get rid of this ArrayOf naming convention.

Santos, that should teach them for now , let's hope they hear this.

best regards @llan





Re: Windows Communication Foundation (Indigo) Problem with xsd element with maxOccurs > 1 when generating the DataContract using svcutil.exe

Carlos Figueira - MSFT

Maxoccurs can definitely be >1 in WCF, but cannot be combined with other elements in the same sequence. Basically, we do not allow bare arrays.

Let's say you have a

<sequence>

<element name="a" />

<element name="b" maxoccurs="3" />

</sequence>

This would correspond to

<a/>

<b/>

<b/>

<b/>

DCS does not allow this - it doesn't map cleanly to structures in most programming languages, which is what the DCS model is based on. If you wrap the array in its own element:

<a/>

<barray>

<b/>

<b/>

<b/>

</barray>

... then the corresponding schema would be valid DCS schema.





Re: Windows Communication Foundation (Indigo) Problem with xsd element with maxOccurs > 1 when generating the DataContract using svcutil.exe

Timothy Wilson

that's true, but isn't

<a/>

<b/>

<b/>

<b/>

wrapped in another element anyway

at the very least

it would have the soap body and method tags surrounding them.