2

I am struggling to understand certain referencing aspects when it comes to WCF and normal references. I have a solution with 4 projects. One project is services and the other three had service references to this project. One project is a base class library that is traditionally referenced in the other three.

I had to update service references in a certain order or VS would get confused about ambiguous references. This was due to the WCF reference being somehow imported through the normal reference so there were two namespaces for everything service related.

I tried to tidy this up by removing service references from all but the base library so this would be the arbiter of WCF connections and no more ambiguity. However I am not sure it is even possible to use a service reference inside another project by way of reference and the services are throwing an endpoint not found exception. I made sure the projects still had end points but they now do not have the references. I assumed the endpoint would come through with the base reference but it appears it is not. Now classes in the base library are also in conflict between the base version and the service version of them.

Basically the references go a little like this:

WCFProject ->serviceReference<- BaseLibrary ->reference<- SiteProject 1 and 2.

How do I get SiteProjects to use WCF services without the service reference in the home project but the one in the BaseLibrary?

  • I should add that I am adding the BaseLibrary namespace when calling the reference like: using(BaseNameSpace.WCFName.ServiceClient etc) – MoustacheDangerous Sep 10 '15 at 18:18
  • It is possible to make service references internal to the assembly from where you added the reference, if you think this may solve your problem. – Biscuits Sep 10 '15 at 18:33
  • I'm not sure @Biscuits I will check if that will help however I think my issue is I am trying to get a project to inherit a service reference from a referenced project and I don't think that's a thing. – MoustacheDangerous Sep 10 '15 at 20:39
  • You speak of a "services project" then "base class library project" and also "home project" and continue to mention 3, which may or may not be the same ones that reference the "base class library project", also have service references. I'm finding it difficult to make sense of this. Which is which? Can you give us 2 clear pictures; one that shows assembly references and another showing service references - but clearly identify the same projects – Biscuits Sep 11 '15 at 01:26
  • @Biscuits sorry for not being clear. The solution has 4 projects and only one is the services project and only one is a referenced project they are separate and the remaining two are web forms sites which both use services and classes in the base library. – MoustacheDangerous Sep 11 '15 at 13:32

2 Answers2

1

For those who stumble upon this I have found a way to use a referenced projects service reference using the following SO thread: Could not find default endpoint element

Community
  • 1
  • 1
0

I think you should start off by asking "why are these references service references, instead of binary references?".

There may well be a good reason for this, for example, the service will be deployed to a separate machine to the other projects in the solution. Another reason would be that to the capabilities provided by the service are not a natural fit for running in-process, and would make the consuming application too complex.

In your scenario, the question would be:

"For each of the three service consumers, would it be possible for me to take advantage of the capabilities of the service by simply referencing the service internals via a binary reference?"

If the answer to this is yes then with a little refactoring you can simply remove the WCF service library code and the service references. Then you will simply have three projects which all host the desired capability in-process when they run.

This is desirable for a few reasons, but here are two:

  1. In-process code is orders of magnitude faster than out-of-process code (like wcf services).
  2. In-process code is much simpler to manage and deploy.

However, if you do need the service's capabilities to remain wrapped in a WCF service, then you can still simplify your solution dramatically by:

  1. Moving the service into its own solution, and
  2. Getting rid of all the service references and using ChannelFactory<T>.CreateChannel() to call the service directly instead.

ChannelFactory works by allowing you to call a service by referencing the service binaries directly. This negates the need for a service reference, which has no shared binary dependencies.

This approach is desirable for many reasons, but here are two:

  1. No need to service references, drastically simplifies your code.
  2. When the service changes, there is no need to update anything; the change is available via binary reference, and is as natural as consuming an assembly in-process.

I often see examples of WCf services included as projects within solutions, where the other projects in the solution consume the service via service reference. This in my mind is not good design. Firstly, a service should never reside under a single solution with it's consumers, and secondly, consumers should consume the service directly and without using service references unless absolutely necessary.

I am not familiar with the process of not using a reference and your solution looks interesting. I will read up on that

Please do. Service references have no place in a scenario where you are in full control of service and consumers. I know this sounds prescriptive but it is bourne out by experience.

The database model library resides in the BaseLibrary and these are used by way of reference in the service project

Which of the projects reference this assembly? If the service uses it then you can move it out of the solution with the service. But do the clients also use this? If so, does this mean clients and service both access the same database? If not, then why do they both make use of the same data models?

Would moving services to another solution not negate this advantage of only having one place for interproject code?

I would strongly disagree that having a single place for interproject code is always a good reason to bunch projects together inside a solution. You can then end up with projects which are completely unrelated to each other (from a business, technology, or capability perspective) sharing a solution just so they can benefit from this "advantage". A better strategy in my opinion is to remove the common assembly into it's own solution, and then publish it to a local NuGet server. Any project which requires this assembly can then retrieve it from NuGet.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • The services will be deployed on a different machine hence the need for the references. I am not familiar with the process of not using a reference and your solution looks interesting. I will read up on that. The database model library resides in the BaseLibrary and these are used by way of reference in the service project. Would moving services to another solution not negate this advantage of only having one place for interproject code? @Tom Redfern – MoustacheDangerous Sep 11 '15 at 13:37
  • @MoustacheDangerous - please see update to my answer based on your comment. – tom redfern Sep 11 '15 at 15:33
  • thank you very much for your elaborations @Tom Redfern. In this instance I don't think I will have the time to move the services out of solution but I think I have realised the issue with something else you said. I have made some bad design decisions and am now paying the price. Thank you for your detailed answer. – MoustacheDangerous Sep 11 '15 at 22:33