简体   繁体   中英

Creating WCF service without .svc file

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?

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.

.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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM