By Michele Leroux Bustamante
Book Price: $44.99 USD
£31.99 GBP
PDF Price: $30.99
Cover | Table of Contents
Service Oriented Architecture (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains.
System.ServiceModel is the assembly that contains core functionality for WCF, which explains why the WCF platform is often called the service model. Any project that exposes or consumes WCF services must reference the System.ServiceModel assembly, and possibly other supporting assemblies.ServiceHost, and channels.ServiceFromScratch. Click OK to create the empty solution.HelloIndigo project from earlier labs and a shell client application.Message type from the System.ServiceModel.Channels namespace. The Message type is essentially a runtime representation of a SOAP message. When serialized, the wire format of the message complies with SOAP 1.1 or 1.2 depending on the binding configuration for the endpoint.Message type also holds addressing headers, consistent with the WS-Addressing standard. These are serialized with the message if the binding supports addressing. When the service model processes messages, other standards may also come into play to add features such as security and reliability. The service model supplies channels for many of the emerging protocols, usually referred to as WS* (pronounced WS-Star). Through bindings (discussed in ), you can enable features that use these protocols. In short, WCF relies on standards to serialize messages; here I'll provide you with an overview in this chapter of the core standards that will be elaborated on throughout this book.Envelope element with two child elements: an optional Header element and a required Body element as follows:
<Envelope>
<Header>
<!-- message headers -->
</Header>
<Body>
<!-- message body elements -->
</Body>
</Envelope>
ServiceDescription type from the System.ServiceModel namespace.ServiceDescription type is a runtime representation of all service endpoints and their associated service contracts, the binding configuration that describes protocol support, and local behaviors that affect how the service model processes messages. It is the ServiceDescription type that is used to generate the WSDL document, and it also supports dynamic metadata exchange so that clients can discover at runtime what protocols are required to invoke service operations. Recall from that SvcUtil is used to generate proxies for clients by consuming a WSDL document or using dynamic metadata exchange, which is based on WS-MetadataExchange protocol (see ).
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 ). 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.
ServiceContractAttribute, OperationContractAttribute, and MessageParameterAttribute. Collectively, these attributes provide control over the way messages are formatted.Host project followed by the DataContractAttribute to a type. To include members in serialization, you decorate them with the DataMemberAttribute; this is an opt-in process that has nothing to do with visibility of members (public, protected, private). By default, serialization is handled by the DataContractSerializer, a new serializer for WCF that succeeds the XmlSerializer used for earlier technologies such as ASMX.IExtensibleDataObject to support version toleranceDataContractAttribute and the DataMemberAttribute, you will control type serialization through the DataContractSerializer. You'll also test data contract version tolerance and implement the IExtensibleData interface in support of versioning.MessageContractAttribute, MessageHeaderAttribute, and MessageBodyMemberAttribute.GigManager project and open GigManagerService.cs. The operations in the service contract look like this:[OperationContract] void SaveGig(LinkItem item); [OperationContract] LinkItem GetGig( );
SerializableAttribute and ISerializableDataContractSerializer:DataContractAttribute or the CollectionDataContractAttribute.SerializableAttribute that optionally implement the ISerializable interface for custom serialization, and types that implement IXmlSerializable.MessageContractAttribute and containing only data contracts or serializable types as header and body members.Message type with direct access to message headers, message body elements, and other properties associated with a SOAP message. Untyped messages like this make it possible to develop generic service operations that do not do the work of serialization and deserialization; instead, they act as a pass-through for messages. Web service intermediaries and content-based routers are examples of service endpoints that can accept any message while still inspecting appropriate message headers or content and forwarding to the rightful recipient.Message type to create and process messagesMessageMessageHeader typeMessage type. Later in this section of the chapter, I'll discuss some more practical uses for working with raw messages as well.IXmlSerializable you can respect preexisting XSD schema while still building a service contract to frame the operations available at an endpoint.IXmlSerializable for situations where the XSD schema has been provided in advance, for example by standards organizations in your industry.NetTcpBinding and BasicHttpBinding to establish communication channels between clients and services. Although I've shown you how to select a binding for a service endpoint, and I've discussed how bindings determine the protocols used to communicate, I haven't begun to show you scope of what bindings can do. In this chapter, I'll focus on bindings, explaining how to choose from the different standard bindings, how to customize them to meet your deployment needs, and how to create custom bindings to address special situations where the standard bindings don't satisfy your requirements. In the process, you'll learn how to work with web service bindings and connection-oriented bindings, how to implement two-way communication scenarios, and how to handle large messages.Binding. Bindings describe the transport protocol, message-encoding format and other messaging protocols for the communication channel. In this section, I'm going to introduce you to each of the standard bindings, explain the features provided by the service model for bindings, and explain how binding configuration builds the communication channel.ServiceHostbinding property for each service or client <endpoint> by referring to it by its configuration name, as shown here:Binding. Bindings describe the transport protocol, message-encoding format and other messaging protocols for the communication channel. In this section, I'm going to introduce you to each of the standard bindings, explain the features provided by the service model for bindings, and explain how binding configuration builds the communication channel.ServiceHostbinding property for each service or client <endpoint> by referring to it by its configuration name, as shown here:// service endpoint <endpoint address="HelloIndigoService" binding="basicHttpBinding" contract="Host.IHelloIndigoService" /> // client endpoint <endpoint address="http://localhost:8000/HelloIndigo/HelloIndigoService" binding="basicHttpBinding" contract="Client.localhost.IHelloIndigoService" />
ServiceHost or client proxy. In either case, you create an instance of the desired binding by its CLR type, for example:BasicHttpBinding basicBinding = new BasicHttpBinding( ); NetTcpBinding tcpBinding = new NetTcpBinding( );
binding property for declarative configuration you refer to the binding by its configuration name.BasicHttpBinding, WSHttpBinding, WSDualHttpBinding, and WSFederationHttpBinding. BasicHttpBinding supports SOAP 1.1 by default, whereas the other three bindings default to SOAP 1.2 with support for WS-Addressing among other protocols.BasicHttpBindng and WSHttpBinding. The first thing you'll do is complete a lab that exercises each binding. After the lab, I'll explain the following concepts:MessageVersion settingsBasicHttpBinding and WSHttpBinding. You'll see how to configure multiple .svc endpoints in a web host.NetNamedPipeBinding wraps communication over named pipes, and limits that communication to the same machine for security reasons (you can be certain your named pipe endpoints cannot be called remotely). NetTcpBinding enables TCP socket communication for RPC and streaming scenarios. In this section, I'll show you how to work with NetNamedPipeBinding and NetTcpBindng endpoints and discuss scenarios in which each binding is most applicable. You'll complete a lab first to put them to use, and then I'll dig into the details.NetPeerTcpBinding is also based on the TCP protocol, offering peer-to-peer communications. This binding has implications beyond WCF and is too broad to cover in this book.NetNamedPipeBinding and NetTcpBinding.
WSDualHttpBinding features