Joe Pinder
Joe Pinder

Reputation: 61

WCF Serialised List object giving strange names for objects

Here is the Method signature in the WCF service:

APIMessageList<APISimpleContact> GetMembers(string apiKey, APIContactSearchFilter filter);


APIMessageList inherits from IList. Once I have built a proxy against this WCF service the class name is APIMessageListOfAPISimpleContactjHldnYZV.

Why do I not get: APIMessageListOfAPISimpleContact?

It adds random text to the end of every APIMessageList object in the interface (there are several) They all end with the same few chars - jHldnYZV. I have looked online for possible causes, but I can't find any posts of people having this problem.

This is a purely cosmetic issue but this interface is exposed to our external customers so its appearance is important.

Anybody know why I am getting this problem?

Many thanks
Joe

Upvotes: 6

Views: 1286

Answers (2)

carlosfigueira
carlosfigueira

Reputation: 87323

Your solution will be at http://msdn.microsoft.com/en-us/library/ms731045.aspx. Basically, since you could have multiple "SimpleContract" classes (in different namespaces), WCF will add a disambiguation hash to the end of the contract name, which is what you have in the 8 chars at the end of the contract name. But you can control that, by using the CollectionDataContract and its Name property:

[CollectionDataContract(Name = "APIMessageListOfSimpleContract")]
public class APIMessageList : IList<SimpleContract> { ... }

Upvotes: 7

Nilesh Gule
Nilesh Gule

Reputation: 1621

We had a similar problem while using Generic types for return values. If we are not specifying a concrete type, the default data contract serializer or the WCF serializer is unable to infer the exact type of the returned entity. Hence it generates a random class name for the returned type.

In our project we overcame this problem by building a data contract which was of specific type and returned the same as a result of a WCF operation call.

My guess is that you are using a generic type and the serializer is unable to infer the type of the returned object.

I suggest you create a Data Transfer Object (DTO) and return the same from the WCF service. That should solve your problem.

Upvotes: 0

Related Questions