Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - [DataContract]

 
 
Old 03-04-2006   #1 (permalink)
Damon Allison


 
 

[DataContract]

I'm trying to use svcutil /dconly to generate [DataContract] objects
from an .xsd file.

I'm running into [DataContract] limitations.

First, I'm not able to use facets in .xsd (except enumeration). For
example, I can't restrict an xs:string element to minLength=0
maxLength=30. If I try, svcutil will fail.

Second, I'm not able to define attributes. Trying to generate objects
using the schema below gives me the following error. It seems that
using DataContract has a limitation that it cannot use attributes. Is
this true? That makes things difficult since attribute is so common.


"Error: Type 'customer' in namespace 'http://vision/customerType' cannot
be imported. Attributes must be optional and from namespace
'http://schemas.microsoft.com/2003/10/Serialization/'. Either fix the
schema to conform to [DataContract] rules or use ImportXmlType or use a
different formatter "


What are the [DataContract] rules and where do I find them? Why do I
need to have all attributes from the microsoft namespace and optional?



Thanks, Damon







<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://vision/customerType"
xmlns="http://vision/customerType"
elementFormDefault="qualified">

<xs:complexType name="customer">
<xs:sequence>

<xs:element name="lastName" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0" />
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- <xs:element name="lastName" type="xs:string" /> -->
<xs:element name="firstName" type="xs:string" />
<xs:element name="middleInitial" type="xs:string" nillable="true" />
<xs:element name="age" type="xs:long" nillable="true" />
</xs:sequence>
<xs:attribute name="id" type="xs:int" />
<xs:attribute name="lang" type="xs:string" />
</xs:complexType>
</xs:schema>


My System SpecsSystem Spec
Old 03-04-2006   #2 (permalink)
Clemens Vasters [MSFT]


 
 

Re: [DataContract]

DataContract aims to be simple and compatible. No facets, no attributes. The
goal is that data contract abstracts away most of the XSD complexity in a
way that the resulting contract is compatible with a maximum number of other
SOAP stacks. And, as it happens, very few support restricted simple data
types and most commonly people stick stuff in elements.

If you indeed need to adapt to an existing XSD/WSDL by hand or you just love
shaping your schemas at will and/or are concerned about the aesthetic
quality of what hits the wire, you must use XmlSerializer. That gives you
attribute support and if you are pushing and pulling on the extensibility
knobs, you might even get facets to work.

http://windowssdk.msdn.microsoft.com...asp?frame=true



"Damon Allison" <dallison@no-spam.vis.cc> wrote in message
news:Oc7Vcr3JGHA.1288@TK2MSFTNGP09.phx.gbl...
> I'm trying to use svcutil /dconly to generate [DataContract] objects from
> an .xsd file.
>
> I'm running into [DataContract] limitations.
>
> First, I'm not able to use facets in .xsd (except enumeration). For
> example, I can't restrict an xs:string element to minLength=0
> maxLength=30. If I try, svcutil will fail.
>
> Second, I'm not able to define attributes. Trying to generate objects
> using the schema below gives me the following error. It seems that using
> DataContract has a limitation that it cannot use attributes. Is this
> true? That makes things difficult since attribute is so common.
>
>
> "Error: Type 'customer' in namespace 'http://vision/customerType' cannot
> be imported. Attributes must be optional and from namespace
> 'http://schemas.microsoft.com/2003/10/Serialization/'. Either fix the
> schema to conform to [DataContract] rules or use ImportXmlType or use a
> different formatter "
>
>
> What are the [DataContract] rules and where do I find them? Why do I need
> to have all attributes from the microsoft namespace and optional?
>
>
>
> Thanks, Damon
>
>
>
>
>
>
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://vision/customerType"
> xmlns="http://vision/customerType"
> elementFormDefault="qualified">
>
> <xs:complexType name="customer">
> <xs:sequence>
>
> <xs:element name="lastName" nillable="true">
> <xs:simpleType>
> <xs:restriction base="xs:string">
> <xs:minLength value="0" />
> <xs:maxLength value="10" />
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
> <!-- <xs:element name="lastName" type="xs:string" /> -->
> <xs:element name="firstName" type="xs:string" />
> <xs:element name="middleInitial" type="xs:string" nillable="true" />
> <xs:element name="age" type="xs:long" nillable="true" />
> </xs:sequence>
> <xs:attribute name="id" type="xs:int" />
> <xs:attribute name="lang" type="xs:string" />
> </xs:complexType>
> </xs:schema>
>



My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46