C# – How to generate the .svc file

cwcfwinforms

I created my first WCF service and tested it on my computer, and it works.

The files present are an interface, an implementation of that interface, and an app.config file.

Now that it is time to host this on a real server with IIS, I was told IIS looks for a .svc file when receiving incoming calls.

Here is what I found:

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.

Can someone please guide me as to how I can create this file so that I may host it?

Thanks!

Best Answer

The thing you need to keep in mind is that IIS is first-and-foremost a web server, and WCF host secondly.

The webserver's job is to render data based on an incoming request. Most of this data is content (the request path correlated directly to a file on the server) but in the case of a WCF service IIS needs to know where to go from here (thus the SVC file and the "directives" to IIS to spin up your service).

All the SVC file is doing is saying that at /x/y/z.svc I have a WCF service which is capable of a lot more than just server-side pages and content files. So please spin it up, make it available and allow my incoming connections to be processed.

If this were a WCF service hosted on it's own dedicated port, this would be a different story because it's no longer contending with additional requests for /Styles/base.css in addition to /MyService/GetSomeObject/.