Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

[DataContract]

Update your Vista Drivers Update Your Drivers Now!!
 
 
Thread Tools Display Modes
Old 03-04-2006   #1 (permalink)
Damon Allison
Guest


 

[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]
Guest


 

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




Vistax64.com 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 2005-2008

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 47 48 49 50 51