Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate the .svc file?

Tags:

c#

winforms

wcf

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!

like image 973
TheGateKeeper Avatar asked Mar 29 '12 13:03

TheGateKeeper


People also ask

What is a .SVC file?

Text file that contains information about a Windows Communication Foundation (WCF) service that can be run using Microsoft Internet Information Services (IIS); includes a WCF-specific processing directive that activates hosted services in response to incoming messages.

Where is .SVC file in WCF?

.svc file in WXF:- asmx file in web services. In other words, 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 .


2 Answers

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

like image 79
Brad Christie Avatar answered Oct 18 '22 01:10

Brad Christie


IIS Hosted .svc file consists of the @ServiceHost directive and attribute, Service.

<% @ServiceHost Service="MyNamespace.MyServiceImplementationTypeName" %>

The value of the Service attribute is the CLR type name of your service implementation. Using this directive is basically equivalent to creating a service host using the following code in your self hosting console program.

new ServiceHost(typeof(MyNamespace.MyServiceImplementationTypeName ));

And If your self hosted application are using WCF configuration like 'endpoint', 'binding',etc in the app.config, you can also put that in web.config. IIS-hosted service use the same configuration elements and syntax as WCF services hosted outside of IIS. (Except something like you can't control base/endpoint address in IIS-hosted service.) And put your precompiled .dll file to application’s \bin directory of your IIS Site.

And the address of IIS-hosted service will be the address of .svc file. (http://localhost/Application1/MyService.svc).

Please check the below msdn - Deploying an IIS-Hosted WCF Service.

http://msdn.microsoft.com/en-us/library/aa751792.aspx

like image 45
Min Min Avatar answered Oct 18 '22 01:10

Min Min