Adding WCF Service Link Does Not Generate Code

Scenario :

  • Website Design for .NET 3.5
  • Visual studio 2010
  • WCF Service Link

Problem :
I am trying to extend a class marked with a DataContract attribute. I, although the generated class was declared partial , so that I could easily extend it. I tried to declare a partial class in the same namespace with the same name, but it doesn't seem to recognize which class it extends. I tried to find the generated code file (Reference.cs), which I thought existed after reading this article inside the help folder, but it wasn’t there. When I tried to go to the class definition, I found out that it was in the compiled library, and the biggest problem is that it was not declared as partial.

Question :
Is this difference due to the fact that I use a website and not a web project? If so, is there a way to make a code generator (which also seems to compile the generated code) to declare the class as partial?

+6
c # wcf
source share
2 answers

Yes, you can declare your DataContract classes partial.

For this you want to use the DTO template. Basically, this means defining β€œcommon” classes in another assembly and having both the Service and the Application that the Service consumes refer to the assembly with your common classes.

So, for example, your assembly of "DTOs" may contain a DTO called "Product". So, you make them partial, and then you decorate the product and which ever other class has WCF attributes like DataContract and DataMember etc.

You are now referencing the DTO assembly with your service project and your web project.

Now, when you go to your web project and click "Add service link", click "Advanced", and you will notice that you can enable the "reuse reference assemblies" option. do it and you will get full control over DataContracts.

+3
source share

Empty client mediation reference classes can indeed be the most difficult problem to solve.

I would recommend that you use the WCF Test Client or the svcutil.exe. command line svcutil.exe. for a service - you can often get a more detailed error description using these tools than with the Visual Studio Service Link Wizard.

In my case, the problems are invariably related to serialization problems or the namespace of the object / graph β€” usually the get and set mismatches in the DataMember properties, the lack of a KnownType for polymorphic objects, or circular references to the graph.

A partial problem should not be a problem. Just make sure that any additional properties you want to serialize are marked as DataMember .

If all else fails, it is recommended that you use serialization / deserialization unit test for your entity / entity.

0
source share

All Articles