Export (0) Print
Expand All

ServiceBehaviorAttribute.IgnoreExtensionDataObject Property

Gets or sets a value that specifies whether to send unknown serialization data onto the wire.

Namespace: System.ServiceModel
Assembly: System.ServiceModel (in system.servicemodel.dll)

public bool IgnoreExtensionDataObject { get; set; }
/** @property */
public boolean get_IgnoreExtensionDataObject ()

/** @property */
public void set_IgnoreExtensionDataObject (boolean value)

public function get IgnoreExtensionDataObject () : boolean

public function set IgnoreExtensionDataObject (value : boolean)

Not applicable.

Property Value

true if unknown serialization data is never sent; otherwise, false. The default is false.

If a type implements the IExtensibleDataObject interface, it stores any extra data it doesn’t know about that comes over the wire when deserializing into that type. For example, if a type Person has members FirstName and LastName, and an element called PhoneNumber comes in, it is stored. When later serializing the type, PhoneNumber will be re-emitted. The problem is that the schema for Person exported by that service only has FirstName and LastName, so Windows Communication Foundation (WCF) generates a schema-invalid instance! If strict schema compliance is important, you can set IgnoreExtensionDataObject to true to turn this re-emitting behavior off.

Regardless IgnoreExtensionDataObject setting, WCF always processes known data (both in and out) and does not throw exceptions when extra data comes in. You can also set this property using the <dataContractSerializer> element in an application configuration file.

The following example shows the use of IgnoreExtensionDataObject and an implementation of IExtensibleDataObject. In this sample, with IgnoreExtensionDataObject set to false, the extra data that the client knows about is round-tripped back to the client.

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Xml;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(Namespace = "http://microsoft.wcf.documentation")]
  public interface ISampleService{
    [OperationContract]
    Person SampleMethod(Person personParam);
  }

  [DataContract(Name="OriginalPerson", Namespace="http://microsoft.wcf.documentation")]
  public class Person : IExtensibleDataObject
  {
    [DataMember]
    public string firstName;
    [DataMember]
    public string lastName;
    [DataMember]
    public string Message;
    [DataMember]
    public XmlNode[] Blob;

    #region IExtensibleDataObject Members
    private ExtensionDataObject data = null;

    public ExtensionDataObject ExtensionData
    {
      get
      {
        return this.data;
      }
      set
      {
        this.data = value;
      }
    }
    #endregion
  }

  [ServiceBehaviorAttribute(
    IgnoreExtensionDataObject=false, 
    ValidateMustUnderstand=false
  )]
  class SampleService : ISampleService
  {
  #region ISampleService Members
    public Person SampleMethod(Person msg)
    {
      Console.WriteLine(msg.firstName);
      Console.WriteLine(msg.lastName);
      Console.WriteLine(msg.Message);

      msg.lastName = "First Name";
      msg.firstName = "Last Name";
      msg.Message = "This is the Reply message.";
 	    return msg;
    }
  #endregion
  }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft