5

I am having issues running few files which contains a wcf service. The service is created without a config file and without a .svc file. Is it possible to run a service without a .svc file. These are 2 simple C# class files which have their full service requirements, like service contracts and operation contracts.

I have tried it calling from another class, but it gives this error:"a project with an output type of class library cannot be started directly"

my question is: is it necessary to have a service.svc file?

Annonymuze
  • 53
  • 1
  • 1
  • 4
  • 3
    No - you can **self-host** the WCF service in a managed app - no *.svc file or anything like that needed - just some code. See [the relevant MSDN documentation](http://msdn.microsoft.com/en-us/library/ms731758.aspx) on how to do that. – marc_s Mar 06 '12 at 10:42

3 Answers3

8

If you don't host your service in IIS, no need for .svc. The reason for .svc in IIS is:

WCF services hosted in IIS are represented as special content files (.svc files) inside the IIS application. This model is similar to the way ASMX pages are represented inside of an IIS application as .asmx files. A .svc file contains a WCF-specific processing directive (@ServiceHost) that allows the WCF hosting infrastructure to activate hosted services in response to incoming messages.

Min Min
  • 6,188
  • 2
  • 19
  • 17
  • 3
    If you host in IIS and your framework version is 4 or above no need in .svc also. Just use [Config Based Activation](http://blogs.msdn.com/b/rampo/archive/2009/10/27/activation-without-svc-files-config-based-activation-cba.aspx) – Mike Sep 21 '12 at 09:07
1

.svc file is required when you host the service in IIS. The file is actually a text file similar to .asmx file. If you open it with any text editor,you would see some details like .asmx file. Such as Language (C#/VB), Service code and Name of the service, Debug etc..

It is not neccessary to have svc file if your not hosting on IIS. Self hosting is example of not having svc file.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
a1ashiish
  • 81
  • 4
1

Take a look at WCF WebAPI it has lots of cool bits and pieces to allow you to do things like hosting outside of IIS or hosting via a Binding. this article guides you through some basic services. http://www.tugberkugurlu.com/archive/introduction-to-wcf-web-api-new-rest-face-ofnet

however do note that even when SelfHosting (running a WCF service inside a windows process) you will still need an executable (ie you cant just run a class library by itself)

undefined
  • 33,537
  • 22
  • 129
  • 198