50 likes | 167 Views
This guide delves into the intricacies of WCF data contracts, specifically using serialization models similar to ISerializable. It covers how to generate data contracts from WSDL/XSD using svctool, with practical examples like the ComplexDataContract. The document addresses challenges related to importing XSD, namespace handling, and duplicate type creation. It also recommends tools, such as SvcTool and XsdDataContractImporter, to enhance performance and manage parent assemblies efficiently. Find solutions to common problems and optimize your WCF data architecture.
E N D
DataContracts in WCF • Serialization Programming Model for WCF • Similar to ISerializable(also supported by WCF) • Can generate from/to WSDL/XSD using svctool • Example: • [DataContract]public class ComplexDataContract{ [DataMember] string name; [DataMember]System.Version version; [DataMember]System.IO.FileInfofileInfo; [DataMember]System.Collections.Generic.List<System.Uri> uriList; [DataMember] System.Data.SqlTypes.SqlInt32 sqlInt; [DataMember]System.Drawing.KnownColorknownColor;}
Import with Import challenges • xs:import references a namespace, but also a physical document • Namespaces in .NET assembly are not bound to the physical document or XML namespace. • Import parent XSD then import chiid XSD. Duplicate types created.
Solutions • SvcTool parameter /references: • Allows parent assemblies to be referenced • Searches for duplicate types • “Custom Tool” for Visual Studio • Generates code when XSD is edited • Integrates with project system
Problems • SvcTool is limited: • Only supports basic types in parent element/type • boolean, byte, dateTime, decimal, double, float, int, long, short, unsignedByte, unsignedInt, unsignedLong, unsignedShort • Critical: Fails if xs:string is included • Option B: • Use XsdDataContractImporter • Would have better performance too