Learning WCF Chapter2 WCF Contracts and Serialization

So far I’ve talked about the standards behind it all,
but in fact WCF hides most of this from the developer by providing a programming interface for designing service contracts and controlling the message format.
Application messaging requirementsare described by contracts in WCF.
There are three types of formal contracts that clients and services rely on to control messaging.

The service contract describes the operations exposed by a particular service endpoint.
Each operation,through parameters and return types,defines the format of request and response messages.

A data contract describes how a complex type is serialized as part of a message.
Data contracts are the preferred way to include complex types in a service contract.

A message contract provides control over the format of the entire SOAP message,
including support for custom message headers and individual body elements that can be described by data contracts.

By default,message serialization is handled by the DataContractSerializer.
This is a new serializer introduced with WCF that requires all types to opt-in their exact requirements for serialization—in compliance with SOA tenets.

The DataContractSerializer can serialize data contracts,message contracts,and other serializable types such as those marked with the SerializableAttribute or those that inherit IXmlSerializable (see Figure 2-2).

Figure 2-2. The DataContractSerializer can serialize message contracts, data contracts, and other serializable types

It is also possible to tell WCF to use the XmlSerializer that ASP.NET web services use (useful only in rare cases).
The XmlSerializer provides much less control over serialization in that all public members are serialized.
I’ll discuss these and other serialization concepts later in this chapter.

As you complete the labs in this chapter,you will practice working with service contracts,data contracts,message contracts,other serializable types,and raw messages.
Throughout,I’ll provide you with practical design tips,discuss approaches in contract versioning,and teach you how to override default serialization behaviors.

SOAP, WSDL, and WS*
It is amazing to think about the simplicity of the early specifications: SOAP and WSDL.
By their simplicity,adoption was promoted—web service platforms appeared left and right.
Interoperability issues quickly surfaced,forcing platform vendors to pay close attention to their XML parsers and SOAP engines to improve consistency in how XML schema and WSDL were interpreted.
In the meantime,standards building on SOAP and WSDL emerged to deal with addressing and routing scenarios,security,large binary attachments,reliable messaging,transactions,policy,and more.
Like with SOAP and WSDL,these advanced standards—collectively labeled WS*—cycle through phases of development and approval,vendor adoption,and interoperability testing.
A healthy collection of these advanced standards have been fully ratified by W3C (www.w3c.org) and OASIS (www.oasis-open.org),
while others are still in the development or approval process.

时间: 2024-08-28 20:58:59

Learning WCF Chapter2 WCF Contracts and Serialization的相关文章

Learning WCF Chapter2 Data Contracts

A data contract describes how CLR types map to XSD schema definitions. Data contracts are the preferred way to enable serialization of complex types included in operation signatures as parameters or return values. You create a data contract by applyi

Learning WCF Chapter2 Service Contracts

A service contract describes the operations supported by a service,the message exchange pattern they use,and the format of each message. The service contract is also the main driver for generating a service description. A valid WCF service implements

Learning WCF Chapter2 Messaging Protocols

In Chapter 1,you were introduced to fundamental WCF concepts,      在章节1中,学习了wcf中的基础概念including how to create and consume a service,           包括如何创建以及调用服务how to host a service and expose endpoints where it can be reached by clients,    如何托管服务,使得客户端可以

跟我一起学WCF(13)——WCF系列总结

引言 WCF是微软为了实现SOA的框架,它是对微乳之前多种分布式技术的继承和扩展,这些技术包括Enterprise Service..NET Remoting.XML Web Service.MSMQ等.WCF推出的原因在于:微软想将不同的分布式技术整合起来,提供一个统一的编程模型,这样对于开发者来说绝对是好事.在过去的2个月时间内,我陆续写了WCF系列文章,这些文章只是自己这段时间学习WCF内容的一个学习过程和笔记,希望通过这种写博文的方式记录下来和总结.本系列并没有对WCF机制做一个深入解析

Learning WCF Chapter2 Service Description

While messaging protocols are responsible for message serialization formats,there must be a way to capture the protocols required to communicate between clients and services. In Chapter 1,you worked with WSDL documents,which describe the requirements

跟我一起学WCF(7)——WCF数据契约与序列化详解

一.引言 在前面博文介绍到,WCF的契约包括操作契约.数据契约.消息契约和错误契约,前面一篇博文已经结束了操作契约的介绍,接下来自然就是介绍数据契约了.所以本文要分享的内容就是数据契约. 二.数据契约的介绍 在WCF中,服务契约定义了可供调用的服务操作方法,而数据契约则是定义了服务端和客户端之间传送的自定义类型,在WCF项目中,必不可少地是传递数据,把客户端需要传递的数据传送到服务中,服务接收到数据再对其进行处理.然而在WCF中,传递的类型必须标记为DataContractAttribute属性

跟我一起学WCF(11)——WCF中队列服务详解

一.引言 在前面的WCF服务中,它都要求服务与客户端两端都必须启动并且运行,从而实现彼此间的交互.然而,还有相当多的情况希望一个面向服务的应用中拥有离线交互的能力.WCF通过服务队列的方法来支持客户端和服务之间的离线工作,客户端将消息发送到一个队列中,再由服务对它们进行处理.下面让我们具体看看WCF中的队列服务. 二.WCF队列服务的优势 在介绍WCF队列服务之前,首先需要了解微软消息队列(MSMQ).MSMQ是在多个不同应用之间实现相互通信的一种异步传输模式,相互通信的应用可以分布在同一台机器

跟我一起学WCF(12)——WCF中Rest服务入门

一.引言 要将Rest与.NET Framework 3.0配合使用,还需要构建基础架构的一些部件.在.NET Framework 3.5中,WCF在System.ServiceModel.Web组件中新增了编程模型和这些基础架构部件. 新编程模型有两个主要的新属性:WebGetAttribute和WebInvokeAttribute,还有一个URI模板机制,帮助你声明每种方法响应使用的URI和动词..NET Framework还提供了一个新的绑定(WebHttpBinding)和新的行为(We

WCF: Hosting WCF In IIS

1. Create an IIS Application as below 2. In the physical path, there're 2 files and 1 App_Code folder a. App_code contains the WCF Service contract and class implementing the contract b. service.svc contains code hosts the service c. Web.config confi