Chapter II data contract.

Bytes array, DataTime, TimeSpan, Guid, Uri, XmlQualifiedName, XmlEle ment and XmlNode
class members m_CurrentPrice, m_CurrentType and m_ticker symbol will certainly, however m_dailyVolume and m_dailyChange not. Non-class members will certainly exist in the XML instance can be based on negligence, and they are still being felt XSD is legal. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.ServiceModel; namespace EssentialWCF {[DataContract (Namespace = "http://EssentialWCF", Name = "StockPrice")] public class clsStockPrice {[DataMember (Name = "CurrentPrice", Order = 0, IsRequired = true)] public double theCurrentPriceNow; [DataMember (Name = "CurrentTime", Order = 1, IsRequired = true)] public DateTime theCurrentTimeNow; [DataMember (Name = "Ticker", Order = 2, IsRequired = true)] public string theTickerSymbol; [DataMember (Name = "DailyVolume", Order = 3, IsRequired = false)] public long theDailyVolumeSoFar; [DataMember ( Name = "DailyChange", Order = 4, IsRequired = false)] public double theDailyChangeSoFar;} [ServiceContract] public class StockService {[OperationContract] private clsStockPrice GetPrice (string ticker) {clsStockPrice s = new clsStockPrice (); s.theTickerSymbol = ticker; s.theCurrentPriceNow = 100.00; s.theCurrentTimeNow = DateTime.Now; s.theDailyChangeSoFar = .012345; s.theDailyVolumeSoFar = 450000; return s;}}} Svcutil.exe t: metadata called for the use of classes defined in the [DataMember] elements generated XSD. The list 2.15 2.16 reveals a list of the code generated XSD. Beware of the order is based on the temperature of the element name in the code attribute definition. Must also beware of non-class members will certainly be defined in the XML metadata into a minOccurs = 0. Example class to ensure its height and width values ??stored always non-negative jiao.jiaoxuefa.com,
class member name in the code are used m_ prefix. Class member name is overloaded so m_notation no need to introduce the service interface defined in the XSD.
symbol [Serializable] types, members did not help with [NonSerializable] symbol
symbol [CollectionDataContract]
symbol types [Serializable] types and end the ISerializable interface
symbol [ DataContract] and [DataMember] attribute list of the types
2.15 shows a class definition, StockPrice, 5 Columbia public data members. Three, ticker, theCurrentPrice and theCurrentTime certainly have, because they use isRequired = true symbol. Some additional [DataMember] personality revealed in the following:
array and aggregation, such as List , Dictionary and Hashtable
in a service within the functional use by the end of the code . Surface in the service, functional services defined in WSDL. In a WCF service, easy to use and process data in mixed types of representation; while in the service surface, using process data from the XML metadata defines said. WCF data contract for the supply of the code definitions. NET CLR types and definitions used in the service the W3C XML metadata surface communication between the definitions irradiation.
using WCF, developers spend more effort in the code and interface semantics, syntax in the XSD and WSDL will spend less effort. XSD and WSDL is not to say that grammar is not important; they are cross-platform interoperability held a monopoly on essential prerequisite. However, the compiler also revealed by the in the. NET language translation of the generated data structure with cross-platform interoperability of XSD and WSDL monopoly that advantage.
[DataContract] attribute, defined in the System.Runtime.Serialization explained in the description of a class deserve to XSD in the WSDL service leaked out. If a class has not [DataContract] attribute, it will not show the current WSDL. The default, XML metadata names and class names and metadata in the target namespace is the same: http://schemas.datacontract.org/2004/07 (by. NET namespace description). Both can be overloaded. You might want to override them to curb the surface leak in the service name. For example, regOrder an internal class name in the Order in the XSD can leak out. 2.16 reveals a list of the names in case of overload and XSD namespace.
[DataMember] attribute, also defined in the System.Runtime.Serializationwww.yinbiao.org, will determine the [DataContract] attribute defines the members included in the XML metadata. In case a member of the class did not help with the [DataMember] to define the attributes, not included in the XML metadata, although it is a class member. By default, class members are not included in the XML metadata definition, this is a choice model. . NET class member of the range, whether public or private, does not affect whether it is included in the XML metadata; be decided by the [DataMember] to severely limited.
built initial CLR types, such as int32 and string
class members of the order by the [DataMember] attribute. In case the order is not [hot] credit card no annual fee for life can be? Bank is somewhat non-permissive _ credit card information has been determined, the element will be in the XSD arranged in alphabetical order. Order is unimportant trivial, but to curb the monopoly of the order is very important for each other. In case you are looking to send a message to a specific measure in order to receive service messages, to curb this property to XML text encoding sequence elements.
a. NET class definition XML metadata
DataContractSerializer serialization type and speak in the WSDL contract leaked them, if they are Italian the following conditions:
inherited from the type
pieces IXmlSerializable For
at the design stage, [DataContract] attribute is used to indicate which class and deserve to be expressed in XSD in the WSDL service leak. [DataMember] attributes which further define the XSD class members deserve included in the surface representation. Run-time, DataContractSerializer class to use [DataContract] and [DataMember] legal to serialize an object into XML. 2.7 reveals a picture. NET ended with each other to end the monopoly system and other XML metadata that.
2011 年 07 月 22 日
2.8 also reveals the picture depicted in the same translation of 2.7, while also revealing to determine the C # and XSD syntax.

No comments allowed