2

In some projects when I add a service reference to a WCF service, it creates datasource files for classes shared in a common class library, however in others the datasources are not created. The Reference.cs file is different where in the first case the types are from the class library and in the latter it's in the Reference.cs file it self. These are not compatible.

What is it that triggers the automatic generation of the datasource files in this case? Advanced options in Add Service Reference dialog are identical so something else must be playing tricks on me.

UPDATE: Turns out the datasource files are not needed. It's the code generated in the Reference.cs file that makes the whole difference. I can manually edit the parameters for the methods to point to the class-library, and it works. This is of course not a solution in the long run, since I have to do this every time I update the Service Reference. Hopefully someone will come along who knows the trigger of this problem.

bleze
  • 101
  • 1
  • 13
  • You mean to say that... You are adding Service Reference to you WCF Service? Or you are adding your WCF Service as a Service Reference to your project? Please show some samples – Sandeep Kushwah Mar 19 '15 at 11:52
  • I have a class library containing some classes. These classes are used as parameters and results from WCF service. When adding Service Reference in a third project (all in same solution), it sometimes creates the .datasource files other times it does not. I need the datasource files and the Reference.cs to use the class library and not new classes created in the Reference.cs. I can even have two different service references in same project and for one the datasources are created, but not for the other. I wonder what triggers VS to create the .datasource files in some cases and not in others. – bleze Mar 19 '15 at 12:15
  • Okay. What you can do is : **Right Click on your Service Reference** then **click Configure Service Reference** and then **uncheck `Reuse types in refrenced assemblies`** then click okay. Hope that will works as you are expecting. – Sandeep Kushwah Mar 19 '15 at 13:18
  • Thanks, but already tried that. It has no effect on the generation of the datasource files. They are still AWOL :( The service and client both uses the same shared class library. I need the autogenerated code in References.cs to point to the class library and not exposing it's own types in the service. – bleze Mar 19 '15 at 13:51
  • No having the classlibrary datasource files will give me errors like this when trying to use the WCF service; Cannot implicitly convert type 'ServiceReference.Language[]' to 'ClassLibrary.Language[]'. Language class is located in the shared classlib. Instead of the classlib datasource files I get datasource files referring to the servicereference and these are declared in the references.cs file which they are not normally when classlib datasource files are autogen. So weird. I have two solutions. One where a project generates the datasource files for classlib and one which does not. – bleze Mar 19 '15 at 14:17

1 Answers1

0

The file is created by VS when you add a service reference. It's used to enable client UI components to bind to the models (data contracts). I don't know why they are not created for "all" services (but I guess it depends on how that service defines and uses data contracts (as in: no contract no data file)).

Here are some useful links: https://msdn.microsoft.com/en-us/library/ee373840.aspx What are the WCF Service Reference .datasource files?

UPDATE: You are right it should not depend on the consumed service. Here are two related links (that impliece that the files are included by VS): http://objectmix.com/dotnet/797048-wcf-service-reference-datasource-file-name-length-problem.html Disable automatic generation of datasources file when updating service references

So it looks like the file is created by VS, if you don't wan/need it you can exclude it by creating the proxy with svcutil.exe

Community
  • 1
  • 1
Jocke
  • 2,032
  • 1
  • 15
  • 22
  • The service cannot be the problem since in some clients the datasource files are created but not in others, for the same service. I need to figure out what triggers this creation. – bleze Mar 19 '15 at 12:18
  • Comment to your update: The point is that VS does NOT generate the files in some projects/solutions. I want it to. Using identical approach in the different projects/solutions. – bleze Mar 19 '15 at 14:53