<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      我的WCF之旅(4):WCF中的序列化[下篇]

      ... ...續Part I([原創] 我的WCF之旅(4):WCF中的序列化(Serialization)- Part I)

      XMLSerializer

      提到XMLSerializer,我想絕大多數人都知道這是asmx采用的Serializer。首先我們還是來看一個例子,通過比較Managed Type的結構和生成的XML的結構來總結這種序列化方式采用的是怎樣的一種Mapping方式。和DataContractSerialzer Sample一樣,我們要定義用于序列化對象所屬的Type——XMLOrder和XMLProduct,他們和相面對應的DataContractOrder和DataContractProduct具有相同的成員。

      using System;
      using System.Collections.Generic;
      using System.Text;

      namespace Artech.WCFSerialization
      {
          
      public class XMLProduct
          
      {
              
      Private Fields

      }



      using System;
      using System.Collections.Generic;
      using System.Text;

      namespace Artech.WCFSerialization
      {
          
      public class XMLOrder
          
      {
              
      private Guid _orderID;
              
      private DateTime _orderDate;
              
      private XMLProduct _product;
              
      private int _quantity;

              
      Constructors

              
      Properties

              
      public override string ToString()
              
      {
                  
      return string.Format("ID: {0}\nDate:{1}\nProduct:\n\tID:{2}\n\tName:{3}\n\tProducing Area:{4}\n\tPrice:{5}\nQuantity:{6}",
                      
      this._orderID,this._orderDate,this._product.ProductID,this._product.ProductName,this._product.ProducingArea,this._product.UnitPrice,this._quantity);
              }

          }

      }

      編寫Serialization的Code.

      調用上面定義的方法,生成序列化的XML。

      <?xml version="1.0" encoding="utf-8"?>
      <XMLOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          
      <OrderID>b695fd18-9cd7-4792-968a-0c0c3a3962c2</OrderID>
          
      <OrderDate>2007-03-09T00:00:00+08:00</OrderDate>
          
      <Product>
              
      <ProductID>23a2fe03-d0a0-4ce5-b213-c7e5196af566</ProductID>
              
      <ProductName>Dell PC</ProductName>
              
      <UnitPrice>4500</UnitPrice>
          
      </Product>
          
      <Quantity>300</Quantity>
      </XMLOrder>

      這里我們總結出以下的Mapping關系:

      1. Root Element被指定為類名。
      2. 不會再Root Element中添加相應的Namaspace。
      3. 對象成員以XML Element的形式輸出。
      4. 對象成員出現的順利和在Type定義的順序一致。
      5. 只有Public Field和可讀可寫得Proppery才會被序列化到XML中——比如定義在XMLProduct中的internal string ProducingArea沒有出現在XML中。
      6. Type定義的時候不需要運用任何Attribute。

      以上這些都是默認的Mapping關系,同DataContractSerializer一樣,我們可以通過在Type以及它的成員中運用一些Attribute來改這種默認的Mapping。

      1. Root Element名稱之后能為類名。
      2. 可以在Type上運用XMLRoot,通過Namaspace參數在Root Element指定Namespace。
      3. 可以通過在類成員上運用XMLElement Attribute和XMLAttribute Attribute指定對象成員轉化成XMLElement還是XMLAttribute。并且可以通過NameSpace參數定義Namespace。
      4. 可以在XMLElement或者XMLAttribute Attribute 通過Order參數指定成員在XML出現的位置。
      5. 可以通過XmlIgnore attribute阻止對象成員被序列化。

      基于上面這些,我們重新定義了XMLProduct和XMLOrder。

      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.Xml.Serialization;

      namespace Artech.WCFSerialization
      {
          
      public class XMLProduct
          
      {
              
      Private Fields

              
      Constructors

              
      Properties

          }

      }


      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.Xml.Serialization;

      namespace Artech.WCFSerialization
      {
          [XmlRoot(Namespace 
      = "http://artech.wcfSerialization/Samples/Order")]
          
      public class XMLOrder
          
      {
              
      private Guid _orderID;
              
      private DateTime _orderDate;
              
      private XMLProduct _product;
              
      private int _quantity;

              
      Constructors

              
      Properties

              
      public override string ToString()
              
      {
                  
      return string.Format("ID: {0}\nDate:{1}\nProduct:\n\tID:{2}\n\tName:{3}\n\tProducing Area:{4}\n\tPrice:{5}\nQuantity:{6}",
                      
      this._orderID,this._orderDate,this._product.ProductID,this._product.ProductName,this._product.ProducingArea,this._product.UnitPrice,this._quantity);
              }

          }

      }

       

      重新進行一次Serialization。我們可以得到下面的XML。

      <?xml version="1.0" encoding="utf-8"?>
      <XMLOrder id="9a0bbda4-1743-4398-bc4f-ee216e02695b" xmlns="http://artech.wcfSerialization/Samples/Order" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        
      <product id="4e3aabe5-3a51-4000-9fd8-d821d164572a" xmlns="Http://Artech.WCFSerialization/Samples/Product">
          
      <name>Dell PC</name>
          
      <producingArea>Xiamen FuJian</producingArea>
          
      <price>4500</price>
        
      </product>
        
      <quantity>300</quantity>
        
      <date>2007-03-09T00:00:00+08:00</date>
      </XMLOrder>

      分析完XMLSerializer的Serialization功能,我們照例來分析它的反向過程—Deserialization。下面的Deserialization的Code。

      調用DeserializeViaXMLSerializer,得到下面的Screen Shot。下面顯示的Order對象的信息和我們利用DataContractSerializaer進行Deserialization是的輸出沒有什么兩樣。不過有趣的是上面多出了兩行額外的輸出:The constructor of XMLProduct has been invocated! The constructor of XMLOrder has been invocated。而這個操作實際上是定義在XMLProduct和XMLOrder的默認(無參)構造函數里的。所此我們可以得出這樣的結論——用XMLSerializer進程Deserialization,會調用的默認(無參)構造函數來初始化對象。 

      DataContractSerializer V.S. XMLSerializer

      上面我們分別分析了兩種不同的Serializer,現在我們來簡單總結一下他們的區別:

      特性

      XMLSerializer

      DataContractSerializer

      默認Mapping

      所有Public Field和可讀可寫Property

      所有DataMember Filed、Property

      是否需要Attribute

      不需要

      DataContract DataMember或者Serializable

      成員的默認次序

      Type中定義的順序

      字母排序

      兼容性

      .asmx

      Remoting

      Deserialzation

      調用默認構造函數

      不會調用



      WCF相關內容:
      [原創]我的WCF之旅(1):創建一個簡單的WCF程序
      [原創]我的WCF之旅(2):Endpoint Overview
      [原創]我的WCF之旅(3):在WCF中實現雙向通信(Bi-directional Communication)
      [原創]我的WCF之旅(4):WCF中的序列化(Serialization)- Part I
      [原創]我的WCF之旅(4):WCF中的序列化(Serialization)- Part II
      [原創]我的WCF之旅(5):Service Contract中的重載(Overloading)
      [原創]我的WCF之旅(6):在Winform Application中調用Duplex Service出現TimeoutException的原因和解決方案
      [原創]我的WCF之旅(7):面向服務架構(SOA)和面向對象編程(OOP)的結合——如何實現Service Contract的繼承
      [原創]我的WCF之旅(8):WCF中的Session和Instancing Management
      [原創]我的WCF之旅(9):如何在WCF中使用tcpTrace來進行Soap Trace
      [原創]我的WCF之旅(10): 如何在WCF進行Exception Handling
      [原創]我的WCF之旅(11):再談WCF的雙向通訊-基于Http的雙向通訊 V.S. 基于TCP的雙向通訊

      [原創]我的WCF之旅(12):使用MSMQ進行Reliable Messaging
      [原創]我的WCF之旅(13):創建基于MSMQ的Responsive Service
      posted @ 2007-03-10 18:04  Artech  閱讀(24827)  評論(50)    收藏  舉報
      主站蜘蛛池模板: 好看的国产精品自拍视频| 国产综合久久久久鬼色| 亚洲熟女乱色综合亚洲图片| 日韩放荡少妇无码视频| 亚洲日韩日本中文在线| 亚洲欧美日韩在线不卡| 国产熟女激情一区二区三区| 狠狠色噜噜狠狠狠狠2021| 久久人与动人物a级毛片 | 国产精品国产精品一区精品| 成人无码午夜在线观看| 免费网站看sm调教视频| 亚洲综合国产成人丁香五| 国产亚洲精品视频一二区| 国产最大成人亚洲精品| 久久99久久99精品免视看国产成人| 亚洲永久精品日韩成人av| 亚洲国产日韩欧美一区二区三区| 国产高清一区二区不卡| 久久精品国产最新地址| 久久久久国产精品人妻电影| 亚洲精品无码日韩国产不卡av| 日韩亚av无码一区二区三区| 日韩大片在线永久免费观看网站| 亚洲国产欧美在线人成AAAA| 99久久婷婷国产综合精品青草漫画| 99e久热只有精品8在线直播| 国产麻豆9l精品三级站| 日本一区二区三区专线| 国产视频不卡一区二区三区| 特级做a爰片毛片免费看无码 | 精品视频在线观看免费观看| 激情综合网五月激情五月| 蜜桃av多人一区二区三区| 免费无码中文字幕A级毛片| 性色av不卡一区二区三区| 亚洲Av综合日韩精品久久久| 河源市| 九九热在线免费视频精品| 国产高清一区二区不卡| 在线无码av一区二区三区|