문제

I've a question about WCF.

I created a WCF service with a MSMQ endpoint. This service is exposed by a Windows Service and the service is consumed by an Asp.net application. My Asp.net application uses an external DLL containing classes and enums (defined by eBay) that I'd like to use in my DataContract. I cannot modify these classes neither I can add attributes.

My DataContract class is like this:

[DataContract]
public class AddItemArgs
{
    [DataMember]
    public ItemType Item { get; set; }
}

This ItemType is the class defined in the external DLL.

Service is created and compiled and is invoked correctly by the client but... there is an error while serializing my parameter that uses one of the classes defined in the DLL. The error is like:

System.Runtime.Serialization.SerializationException: Type ’System.DelegateSerializationHolder+DelegateEntry‘ with data contract name ’eBay.Service.Core.Soap.BuyerPaymentMethodCodeType:BuyerPaymentMethodCodeType:http://schemas.datacontract.org/2004/07/eBay.Service.Core.Soap’ is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

This problem is VERIFIED when I pass that parameter (BuyerPaymentMethodCodeType). Is this because BuyerPaymentMethodCodeType is an enum type? If i don't pass an ItemType with that field, everything goes fine.

도움이 되었습니까?

해결책

Have you tried:

[DataContract]
[KnownType(typeof(BuyerPaymentMethodCodeType))]
public class AddItemArgs
{

}

As far as enumerations go, here is also some guidance on using the EnumMemberAttribute

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top