![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |