当前位置: 首页 > 工具软件 > Indigo Engine > 使用案例 >

PDC-第2天-WSV303-Indigo,在Web服务中使用XSD,CLR类型和序列化

戚翰飞
2023-12-01

I'm here sitting with Rory in the Xml Serialization talk being given by the legendary Doug Purdy.  Doug's quite a good speaker and very funny.

我在传奇的Doug Purdy发表的Xml序列化演讲中和Rory一起坐在这里。 道格的讲话很好,很有趣。

Lengendary? Why?  Well, not only is he responsible for the goodness that is the XmlSerializer, he's also responsible (or he knows the guy who is) for this undocumented switch:
      <ADD value="1" name="XmlSerialization.Compilation" />

传说中的? 为什么? 好吧,他不仅要为XmlSerializer的优点负责,而且还要为这个未公开说明的开关负责(或他知道是谁): <ADD value =“ 1” name =“ XmlSerialization.Compilation” />

If you add this to a .config file (for your AppDomain) you'll get some temporary files in c:\documents and settings\local settings\ \temp.  Try it.  Run some serialization code and checkout the .CS file(s) that are created.  Very damn useful.  This works today with .NET.

如果将此文件添加到.config文件(对于您的AppDomain),则会在c:\ documents and settings \ local settings \中获得一些临时文件。 \ temp。 试试吧。 运行一些序列化代码,并检出创建的.CS文件。 该死的非常有用。 如今,它可与.NET一起使用。

But I'm here to hear about new versions of stuff.  Here's some new things about XmlSerialization in the Whidbey version of .NET.

但是我在这里听到有关新版本内容的信息。 这是.NET的Whidbey版本中有关XmlSerialization的一些新东西。

  • There's a tool called SGEN that will “NGEN” your serialization code. That way you don't need to take the initial hit when the Serialization Assembly is emited.  You can basically ship it with the code.

    有一个名为SGEN的工具将“ NGEN”您的序列化代码。 这样,在发出序列化程序集时,您无需采取任何措施。 您基本上可以将其与代码一起运送。
  • Adding support for Generics to the Serializer, both open generics and instatiated generics

    向序列化器添加对泛型的支持,包括开放式泛型和实例化的泛型
  • Support for Extensibility around Schema Importing

    支持围绕架构导入的可扩展性
  • SqlType support

    SqlType支持
  • The BinaryFormatter is Version Tolerant

    BinaryFormatter具有版本兼容性
  • Here's some new Attributes:

    这是一些新属性:

    • [OptionalSerializable] - Does just what you'd think.  Makes a field optional, and consequently helps you deal with Version changes between Object Heirarchies

      [OptionalSerializable]-做到您所想。 使字段成为可选字段,从而帮助您处理对象层次结构之间的版本更改

Here's what's going on with XmlSerialization in Indigo (after Whidbey, in Longhorn):

这是Indigo中的XmlSerialization发生的事情(在Whidbey之后,在Longhorn中):

  • The Serializer is now in the Core

    序列化器现在位于核心
  • Architecture of the CLR, not just “tacked on“

    CLR的体系结构,而不仅仅是“紧贴”
  • A Tale of Two Type Systems

    两种系统的故事

    • Act One: Whidbey

      第一幕:惠德比

      • Mapping XSD into the CLR is very challenging, including mapping some of the concepts that exist in XSD that just don't in the CLR

        将XSD映射到CLR非常具有挑战性,包括映射XSD中存在的一些概念,而这些概念只是CLR中不存在的
      • Mapping from the CLR to XSD is fairly straightforward

        从CLR到XSD的映射非常简单
      • CLR to CLR is really easy

        从CLR到CLR真的很容易
    • Act Two: Indigo

      第二幕:靛蓝

      • Big Conclusion - Serialization is different than Xml Programming.  Developers don't think about the format on the wire.  They want the CLR to fix it for them.

        大结论-序列化与Xml编程不同。 开发人员不会考虑在线格式。 他们希望CLR为他们修复它。

      • New stack: XmlFormatteer consiting of Serialization Engine -> Extensibility -> Xml Processing - Representations

        新堆栈:序列化引擎的XmlFormatteer含义->可扩展性-> Xml处理-表示形式
      • XmlBinaryReader and XmlBinaryWriter being introduced

        引入了XmlBinaryReader和XmlBinaryWriter
      • Allow the developer to express the data contract for a given type Explicitly

        允许开发人员明确表达给定类型的数据合同
      • [DataMember] lets you markup any member and include it into the Data Contract.  It doesn't care about accessiblity.  That means you can mark something private or internal and if it's marked with [DataMember] then it gets serialized.

        通过[DataMember] ,您可以标记任何成员并将其包括在Data Contract中。 它不在乎可访问性。 这意味着您可以将某些内容标记为私有或内部,如果标记为[DataMember],则会对其进行序列化。

      • Cool...you can have two totally “different“ CLR types, perhaps one has a private something with a property accessor and another version has the same “semantic“ member but it's public.  You can mark them up with DataMember to make the contract with the serializer the same so the objects will serialize the same.

        太酷了……您可以有两种完全“不同的” CLR类型,也许一种具有带有属性访问器的私有属性,另一种具有相同的“语义”成员,但它是公共的。 您可以使用DataMember对其进行标记,以使与序列化程序的协定相同,以便对象将对序列化相同。
      • WHY IS THIS IMPORTANT: You can serialize one CLR object from one Assembly and deserialize it into another totally different implemenation (a totally different CLR type).  As long as we both agree on the contract, we can use the same underlying data representation.  Yum.

        为什么这样做很重要:您可以从一个Assembly中序列化一个CLR对象,并将其反序列化为另一种完全不同的实现(一种完全不同的CLR类型)。 只要我们双方都同意合同,就可以使用相同的基础数据表示形式。 好吃

  • Existing Types continue to work, but you get loose coupling and version resiliance

    现有类型可以继续使用,但是耦合和版本弹性会松散

Doug said he woke up this morning hoping the sky would be Indigo.  It wasn't.  But one day...

道格说他今天早上醒来,希望天空是靛蓝。 不是。 但是有一天

P.S. I forgot to mention that Christian Weyer can lift Rory with ease.  If he were Austrian, he could be a governor.

言:我忘了提克里斯蒂安·韦耶(Christian Weyer)可以轻松举起罗瑞(Rory) 如果他是奥地利人,他可以担任州长。

翻译自: https://www.hanselman.com/blog/pdc-day-2-wsv303-indigo-using-xsd-clr-types-and-serialization-in-web-services

 类似资料: