Known Types and Service Known Types

Endpoint 사이의 메세지 직렬화때문에, 객체의 자동형변환이 가능하지 않다.
가능하게 하기 위해서는 명시적으로 derived 타입을 알려줘야 한다.

The solution is to explicitly tell WCF about the Customer class using the KnownTypeAttribute,
defined as:

[AttributeUsage(AttributeTargets.Struct|AttributeTargets.Class, 
AllowMultiple = true)]
public sealed class KnownTypeAttribute : Attribute
{
   public KnownTypeAttribute(Type type);
   //More members
}

[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Class, 
AllowMultiple = true)]
public sealed class ServiceKnownTypeAttribute : Attribute
{
   public ServiceKnownTypeAttribute(Type type);
   //More members
}

WCF lets you configure the known types in the service’s or client’s config file,
as shown in Example 3-6. You need to provide not just the type names, but also the names of their containing assemblies.

When not relying on string name or assembly version resolution, you can just use the assembly-friendly name:

Or use Data Contract Resolvers.

댓글

이 블로그의 인기 게시물

Oracle NLS_DATE_FORMAT 변경

Alternative to IValueConvert, QuickConverter

Reflection with IDispatch-based COM objects