WCF Serialized List object giving strange names to objects

Here is the method signature in the WCF service:

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


APIMessageList inherited from IList . Once I have built a proxy against this WCF service, the class name will be APIMessageListOfAPISimpleContactjHldnYZV.

Why am I not getting: APIMessageListOfAPISimpleContact ?

It adds random text to the end of each APIMessageList object in the interface (there are several of them). They all end with the same number of characters - jHldnYZV. I looked online for possible reasons, but I cannot find any posts about people having this problem.

This is a purely cosmetic problem, but this interface is available to our external customers, so its appearance is important.

Does anyone know why I am getting this problem?

Thank you so much joe

+6
source share
2 answers

Your solution will be http://msdn.microsoft.com/en-us/library/ms731045.aspx . Basically, since you can have several SimpleContract classes (in different namespaces), WCF will add a value hash to the end of the contract name, which is 8 characters at the end of the contract name. But you can control this using the CollectionDataContract property and its name:

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

We had a similar problem when using Generic types for return values. Unless we specify a specific type, the default data serializer or WCF serializer cannot determine the exact type of the returned object. Therefore, it generates a random class name for the return type.

In our project, we overcame this problem by building a contract with a specific data type and returning to the result of invoking the WCF operation.

I assume that you are using a generic type and the serializer cannot infer the type of the returned object.

I suggest you create a data transfer object (DTO) and return it using the WCF service. This should solve your problem.

0
source

Source: https://habr.com/ru/post/894197/


All Articles