ServiceBehaviorAttribute.IgnoreExtensionDataObject Property


取得或設定值,這個值會指定是否要將未知的序列化資料傳送到網路上。Gets or sets a value that specifies whether to send unknown serialization data onto the wire.

 property bool IgnoreExtensionDataObject { bool get(); void set(bool value); };
public bool IgnoreExtensionDataObject { get; set; }
member this.IgnoreExtensionDataObject : bool with get, set
Public Property IgnoreExtensionDataObject As Boolean

Property Value


如果絕不傳送未知的序列化資料,則為 true,否則為 falsetrue if unknown serialization data is never sent; otherwise, false. 預設值為 falseThe default is false.


下列範例會示範 IgnoreExtensionDataObject 的使用和 IExtensibleDataObject 的實作。The following example shows the use of IgnoreExtensionDataObject and an implementation of IExtensibleDataObject. 在這個範例中,藉由將 IgnoreExtensionDataObject 設定為 false,用戶端便會將所知道的額外資料再傳回用戶端。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{
    Person SampleMethod(Person personParam);

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

    #region IExtensibleDataObject Members
    private ExtensionDataObject data = null;

    public ExtensionDataObject ExtensionData
      { = value;

  class SampleService : ISampleService
  #region ISampleService Members
    public Person SampleMethod(Person msg)

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


如果型別會執行 IExtensibleDataObject 介面,它會儲存在還原序列化為該類型時,透過網路所不知道的任何額外資料。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. 例如,如果型別 Person 具有成員 FirstNameLastName,這時若有個 PhoneNumber 的項目進入,該項目便會被儲存起來。For example, if a type Person has members FirstName and LastName, and an element called PhoneNumber comes in, it is stored. 當稍後序列化此型別時,PhoneNumber 將會重新發出。When later serializing the type, PhoneNumber will be re-emitted. 問題是該服務所匯出 Person 的架構只有 FirstNameLastName,因此 Windows Communication Foundation (WCF)會產生架構不正確實例!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! 如果嚴格的結構描述相容性很重要,您可以將 IgnoreExtensionDataObject 設定為 true,以便關閉這個重新發出的行為。If strict schema compliance is important, you can set IgnoreExtensionDataObject to true to turn this re-emitting behavior off.

無論 IgnoreExtensionDataObject 設定為何,WCF 一律會處理已知資料(傳入和傳出),而且不會在額外資料進入時擲回例外狀況。Regardless IgnoreExtensionDataObject setting, WCF always processes known data (both in and out) and does not throw exceptions when extra data comes in. 您也可以使用應用程式佈建檔中的<dataContractSerializer>元素來設定此屬性。You can also set this property using the <dataContractSerializer> element in an application configuration file.

Applies to