ServiceBehaviorAttribute.IgnoreExtensionDataObject Propriedade
Definição
Obtém ou define um valor que especifica se dados de serialização desconhecidos serão enviados na conexão.Gets or sets a value that specifies whether to send unknown serialization data onto the wire.
public:
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
Valor da propriedade
true se os dados de serialização desconhecidos nunca forem enviados; caso contrário, false.true if unknown serialization data is never sent; otherwise, false. O padrão é false.The default is false.
Exemplos
O exemplo a seguir mostra o uso de IgnoreExtensionDataObject e uma implementação de IExtensibleDataObject .The following example shows the use of IgnoreExtensionDataObject and an implementation of IExtensibleDataObject. Neste exemplo, com IgnoreExtensionDataObject definido como false , os dados extras que o cliente sabe são voltados para o cliente.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
}
}
Comentários
Se um tipo implementar a IExtensibleDataObject interface, ele armazenará todos os dados extras que não souber que são transmitidos pela conexão durante a desserialização nesse tipo.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. Por exemplo, se um tipo Person tiver membros FirstName e LastName , e um elemento chamado PhoneNumber chegar, ele será armazenado.For example, if a type Person has members FirstName and LastName, and an element called PhoneNumber comes in, it is stored. Quando, mais tarde, a serialização do tipo PhoneNumber será emitida novamente.When later serializing the type, PhoneNumber will be re-emitted. O problema é que o esquema para Person exportado por esse serviço tem apenas FirstName e LastName , portanto Windows Communication Foundation (WCF) gera uma instância de esquema inválida!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! Se a conformidade de esquema estrita for importante, você poderá definir IgnoreExtensionDataObject como true para desativar esse comportamento de reemissão.If strict schema compliance is important, you can set IgnoreExtensionDataObject to true to turn this re-emitting behavior off.
Independentemente IgnoreExtensionDataObject da configuração, o WCF sempre processa dados conhecidos (dentro e fora) e não gera exceções quando dados adicionais chegam.Regardless IgnoreExtensionDataObject setting, WCF always processes known data (both in and out) and does not throw exceptions when extra data comes in. Você também pode definir essa propriedade usando o elemento < DataContractSerializer > em um arquivo de configuração de aplicativo.You can also set this property using the <dataContractSerializer> element in an application configuration file.