views:

148

answers:

1

Hi everybody, 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.

+2  A: 

Have you tried:

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

}

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

RandomNoob
I already tried that but it didn't work even if i selected Update service reference. Due to your suggestion I tried to remove the reference and add it back again. Will let you know in some minutes. It seems to work for that enum type.Thanks, Marco
IT DO WORKS! Thank you a lot bnkdev!
Thanks, if this has solved the problem, maybe accept the answer so others may benefit. Glad it worked.
RandomNoob