Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service that returns a custom class generates errors in Reference.cs

I have a WCF Service project in Visual Studio 2008 that contains about 12 methods, some of which return primitive types like bool or string. I also have a Visual Studio Unit Test Project that references the published WCF Service. The Test Project compiles successfully when all the return types are primitive.

If I add a new method to the service that returns a custom class, publish it and update the service reference in the Test Project, it doesn't compile. The errors are: -

  1. The type 'PublisherFaultException' already contains a definition for 'Reason'.
  2. The type 'PublisherFaultException' already contains a definition for 'PropertyChanged'.
  3. Type 'Publisher.Test.LibraryReference.PublisherFaultException' already defines a member called 'RaisePropertyChanged' with the same parameter types.

all in the auto-generated reference.cs file.

The contract for the method of the WCF Service is: -

Page GetItem(string path);

and the Page class has the DataContract attribute and it's public properties have the DataMember attribute.

I'm reluctant to modify the Reference.cs file as I'll need to do this every time the Service is updated.

Anyone know why this is happening?

Stuart.

like image 372
Stuart Whiteford Avatar asked Oct 29 '09 10:10

Stuart Whiteford


1 Answers

When you Add Service Reference, you get a 'reuse types in assembly' option - this is likely to be the key to sorting out the duplication.

Or do you have some Test References that are causing the duplication?

Also, have a look in the References section of the project tree and see if there is anything unexpected in there (do you have references to 2 assemblies that both contain Service References in the same namespace?).

like image 63
Ruben Bartelink Avatar answered Oct 05 '22 23:10

Ruben Bartelink