1

I have a C#/WCF service. I'm having problems adding a service reference to it, so one of my colleagues suggested that I simply add a reference to it using a library.

The second answer here suggests that by doing so I lose the service re usability.
Is that correct? Are there any other differences between those options?

Edit
I have no experience with WCF. I was working according to this tutorial, please provide some explanations (or links to them) in your answers as well.

Edit 2
I want a Windows-hosted WCF service that will run on every machine that runs my main application. My application (and another one) will use this service locally only.
Can I still achieve that with "Add reference"?

Edit 3
I need a service because I have two different application that are doing the same thing and they need HW resources for that. Currently, one of them is using the other's dll, so the code is not copied and pasted (at least), but there's no way to prevent a concurrent access to those resources. Windows service can solve this problem.
The binding is not too important. I'll read further about named pipes.

Community
  • 1
  • 1
Noich
  • 14,631
  • 15
  • 62
  • 90

4 Answers4

0

Add reference is add reference to dll, exe etc

Add service referenceis create proxy-class to some service

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
  • I understand that, but I can still access my service via it's interfaces, if they're defined in a separate dll, can't I? – Noich Mar 12 '13 at 09:32
0

When you use Add service reference, Visual Studio uses svcutil.exe to creates clients proxies (and additionally web.config or app.config files) - special classes, that describe methods on the serverside (service contract). When you know this contract and you have propper configuration - you can call these methods from the server-service remotly.

When you use Add reference - you simply add a new library, which you can use to work the classes, interfaces, methods, which are implemented there. If you have a service contract class in dll, you can use it, instead of creating it with svcutil.exe. But you have to configure it's settings (binding and adress)

Edit 1 There are many examples of creating WFC services. See http://www.codeproject.com/Articles/42643/Creating-and-Consuming-Your-First-WCF-Service or http://www.codeproject.com/Articles/412363/How-to-Use-a-WCF-Service-without-Adding-a-Service. And explanations you want? You just have to make contract(you class with methods), link it to your client and server apps and define proper binding, which describes how to send you contract data between them

Edit 2 It is hard to say, what you have to use without knowing the aim of your application. Therefore, yes, you can use local windows service to host wcf service there. There exists a special type of WCF services for such things which is called NamedPipe - localy hosted services. See http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx for description and http://msdn.microsoft.com/en-us/library/ms733069.aspx for implementation

Alex
  • 8,827
  • 3
  • 42
  • 58
0

Add reference is used to consume the dll or exe files in the project where as add service reference is used to add consume a service. Add service reference will create the Proxy in the project

0

You main application runs on every client machine, while your WCF service runs on a server. You don't run the WCF service on every client, that doesn't make sense.

So you would typically:

  • create a client application
  • create a WCF service
  • add a service reference from your client application to your WCF service

Deploying:

  • deploy your client application to every client computer that wants to use it
  • deploy your WCF service to one or more a server machines
L-Four
  • 13,345
  • 9
  • 65
  • 109
  • Why it doesn't make sence. What about NamedPipe Bindings? http://stackoverflow.com/questions/7353670/wcf-named-pipe-minimal-example – Alex Mar 12 '13 at 10:07
  • Where do you see that TS needs named pipes? – L-Four Mar 12 '13 at 10:17
  • "I want a Windows-hosted WCF service that will run on every machine that runs my main application. My application (and another one) will use this service locally only" - doesn't it suits for NamedPipes? – Alex Mar 12 '13 at 10:23
  • Due to the fact that TS is probably new at this (Difference between “Add reference” and “Add service reference”?) I think we have to challenge this solution as this seems a strange thing to do. Maybe TS should explain first what he really wants to do. – L-Four Mar 12 '13 at 10:32
  • I agree, to little info. But from what TS wrote, it possibly could be the way to go, if she decides to use WCF on her local services. – Alex Mar 12 '13 at 10:40