3

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: Screenshot of reusing referenced assemblies

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

enter image description here

Scott Baker
  • 10,013
  • 17
  • 56
  • 102
  • 1
    When running svcutil, did you use the `/reference` parameter to point it to the DLL with your data contract classes? – vesan Jul 08 '14 at 00:46
  • 1
    It sounds like the tool is generating the types. Do you have 'reuse types in all references assemblies checked'? – Ritch Melton Jul 08 '14 at 00:47
  • @RitchMelton I definitely have "reuse types" checked, and I've selected the assembly ... although I was having trouble with it importing a second version of my assembly earlier - how can I make sure it's referencing the right version? Could the version be the problem? – Scott Baker Jul 08 '14 at 05:36
  • @vesan I don't think so - I'll try that tomorrow. – Scott Baker Jul 08 '14 at 05:37
  • Are you adding reference from `bin` or `debug` folder? – Pranav Singh Jul 09 '14 at 05:16

1 Answers1

1

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: enter image description here

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

Community
  • 1
  • 1
Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
  • Please see edit 2 - despite configuring it as you describe, the service reference is still generating unique classes. – Scott Baker Jul 08 '14 at 14:02