Partilhar via


POCO Support

Download sample

This sample demonstrates the serialization support for unmarked types; that is, types to which serialization attributes have not been applied, sometimes referred to as Plain Old CLR Object (POCO) types. The DataContractSerializer infers a data contract for all public unmarked types that have a default constructor. Data contracts allow you to pass structured data to and from services. For more information about unmarked types, see Serializable Types.

This sample is based on the Getting Started Sample, but uses complex numbers instead of primitive numeric types. It is also similar to the Basic Data Contract sample, except that the DataContractAttribute and DataMemberAttribute attributes are not used.

The service is hosted by Internet Information Services (IIS) and the client is a console application (.exe).

Note

The WCF samples may already be installed on your machine. Check this (default) directory before continuing.

<InstallDrive>:\Samples\WCFWFCardspace

If this directory does not exist, click the download sample link at the top of this page. Note that this link downloads and installs all of the WF, WCF, and CardSpace samples. The sample is located in the following directory.

<InstallDrive>:\Samples\WCFWFCardSpace\WCF\Basic\Contract\Data\POCO

Note

The set-up procedure and build instructions for this sample are located at the end of this topic.

The ComplexNumber class is used in the ServiceContract. The ComplexNumber type does not have the DataContractAttribute and DataMemberAttribute attributes, as shown in the following sample code. By default, all public properties and fields are serialized.

public class ComplexNumber
{
    public double Real;
    public double Imaginary;
    public ComplexNumber()
    {
        Real = double.MinValue;
        Imaginary = double.MinValue;
    }
    public ComplexNumber(double real, double imaginary)
    {
        this.Real = real;
        this.Imaginary = imaginary;
    }
}

To set up, build, and run the sample

  1. Ensure that you have performed the One-Time Set Up Procedure for the Windows Communication Foundation Samples.

  2. To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.

  3. To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.

See Also

Reference

IgnoreDataMemberAttribute

Other Resources

Serializable Types

© 2007 Microsoft Corporation. All rights reserved.