I have a WCF service project that builds fine, makes an accessible WSDL, and svcutil.exe generates no errors.
I have a "Service Manager" project that access that web service, and to which I have successfully added a Service Reference ABCService.
A third project holds all the POCO objects that I need to pass back and forth - decorated liberally with [DataContract] and [DataMember] attributes.
When I try to build the solution, I see that Reference.cs for the ABCService has methods like this (I have substituted (...) for the full namespaces for brevity):
public (...).Thing SaveThing((...).Thing objThing) {
return base.Channel.SaveThing(objThing);
}
public (...).myCollectionOfThing0mj5ZrAW GetThings() {
return base.Channel.GetThings();
}
The first method, that returns a single Thing, works fine - but I get an error for every MyCollection method:
Error 16 Argument 1: cannot convert from '(...).MyCollection<Thing>' to '(...).myCollectionOfThing0mj5ZrAW'
My collection class is decorated as you'd expect:
[CollectionDataContract]
public class MyCollection<T> : List<T> where T : BaseType
{
// ...
}
I have no idea why it's generating the funky "myCollectionOfThing0mj5ZrAW" name, or why the translation from one to the other is failing
EDIT 1: I have tried using
[CollectionDataContract(Name= "myCollection{0}", ItemName = "{0}")]
to decorate my collection class, and I get the same error but with updated names:
Error 12 Argument 1: cannot convert from '(...).myCollection<(...).Thing>' to '(...).myCollectionThing'
EDIT 2:
Despite having checked the "Reuse types in referenced assemblies", selected the radio button for "specified referenced assemblies", and checking the box next to my POCO assembly:

...the service reference is STILL being generated with unique class names:

As suggested by @vesan & @RitchMelton in comments, it seems types are regenerated at client and you should reuse the DataContract.
If you are adding service reference, reuse the type in referenced assemblies by selecting radioreuse types in all references assemblies:

Also note you might need to change collection type to System.Collection.Generic.List to prevent changing of List to Arrays/
If you are generating proxy using SvcUtil, you need to use /reference: to reuse DataContract assemblies while generating reference like:
svcutil /reference:YourDLL.dll http://localhost/YourService?wsdl
For more details on /refernce with SvcUtilrefer:
ServiceModel Metadata Utility Tool (Svcutil.exe)
svcutil exlude/reuse refrenced assemblies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With