Home > Articles > Operating Systems, Server

Data Representation in Windows Communication Foundation

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Craig McMurtryMarc MercuriNigel Watling 

Learn more…

Sorry, this author hasn't written any articles.

Sorry, this author doesn't have anything for sale.

Sorry, this author hasn't posted any blogs.

How is data sent from a Windows Communication Foundation client to a service? This chapter explains the involvement of XML serializers to improve control and optimization.

In This Chapter

  • Background
  • XmlSerializer and XmlFormatter
  • The XML Fetish
  • Using the XmlFormatter
  • Exception Handling

Background

The Windows Communication Foundation provides a language, called the Service Model, for modeling software communications. Software executables can be generated from models expressed in that language using the classes of a lower-level programming framework called the Channel Layer.

In the language of the Service Model, a piece of software that responds to communications over a network is a service. A service has one or more endpoints to which communications can be directed. An endpoint consists of an address, a binding, and a contract.

The role of the address component is simple. It specifies a unique location for the service on a network in the form of a uniform resource locator.

The binding specifies the protocols for communication between the client and the server. Minimally, the binding must specify a protocol for encoding messages and a protocol for transporting them.

A contract specifies the operations that are available at an endpoint. To define a contract, one merely writes an interface in one's preferred .NET programming language, and adds attributes to it to indicate that the interface is also a Windows Communication Foundation contract. Then, to implement the contract, one simply writes a class that implements the .NET interface that one has defined.

This contract was used to define the operations of a derivatives calculator service in Chapter 2, "The Fundamentals."

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

namespace DerivativesCalculator
{
    [ServiceContract]
    public interface IDerivativesCalculator
    {
        [OperationContract]
        decimal CalculateDerivative(
            string[] symbols,
            decimal[] parameters,
            string[] functions);

      void DoNothing();
    }
}

One way of writing code for a client of that service that is to use the CalculateDerivative() operation would be to write this:

string[] symbols = new string[]{"MSFT"};
decimal[] parameters = new decimal[]{3};
string[] functions = new string[]{"TechStockProjections"};

IDerivativesCalculator proxy =
  new ChannelFactory<IDerivativesCalculator>("CalculatorEndpoint").
  CreateChannel();
proxy.CalculateDerivative(symbols, parameters, functions);
((IChannel)proxy).Close();

When the statement

proxy.CalculateDerivative(symbols, parameters, functions);

is executed, the data being provided by the client as input to the operation is added to an instance of the Message class of the Windows Communication Foundation's Channel Layer. Within the Message class, the data is represented in the form of an XML Information Set (InfoSet). When the data is ready to be transported from the client to the service, the message-encoding protocol specified in the binding will determine the form in which the Message object containing the data provided by the client will be represented to the service. The message-encoding protocol could conceivably translate the message into a string of comma-separated values, or into any format whatsoever. However, all the standard bindings specify encoding protocols by which the Message object will continue to be represented as an XML InfoSet. Depending on the encoding protocol of the binding, that XML InfoSet may be encoded either using one of the standard XML text encodings, or the standard MTOM protocol, or using a binary format proprietary to the Windows Communication Foundation.

When a transmission is received by a Windows Communication Foundation service, it is reassembled as a Message object by a message-encoding binding element, with the data sent by the client being expressed within the Message object as an XML InfoSet, regardless of the format in which it was encoded by the client. The Message object will be passed to a component of the Windows Communication Foundation called the dispatcher. The dispatcher extracts the client's data items from the XML InfoSet. It invokes the method of the service that implements the operation being used by the client, passing the client's data items to the method as parameters.

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

 Big Nerd RanchAsk Big Nerd Ranch: Blocks in Objective-C
By Big Nerd Ranch on June 24, 2010 No Comments

Adam Preble answers a question about blocks.

How Long?
By John Traenkenschuh on May 28, 2010 No Comments

John is in shock as the Apple Juggernaut rolls forward.  How long before Win Mobile gets the respect it deserves?

 Big Nerd RanchAsk Big Nerd Ranch: Detecting That QuickTime Has Exhausted Its Stream
By Big Nerd Ranch on March 5, 2010 No Comments
Jeremy W. Sherman answers a question about QuickTime.

Q. If a QTMovie is loading audio from the web and the stream stops, how can I detect whether the QTMovie stopped?

A. Suppose you have a QTMovieView playing a QTMovie. The QTMovie is loading media from the Web. Now, suppose your network connection drops.

What happens next depends on the structure of the movie file itself. The movie file might contain the data itself, or it might reference a broadcast stream.

See All Related Blogs

Informit Network