Xander
Xander

Reputation: 9171

Where is my svc file when i make a WCF in a class library

I created a class library with two wcf services in them. When adding a wcf item it did not add a svc file.

Do I have to manually add them to my main web project?

How might I go about this?

Upvotes: 3

Views: 4385

Answers (2)

Tim
Tim

Reputation: 28530

Which version of .NET are you using? As of 4.0, the *.svc file is no longer needed for IIS-hosted WCF services.

As Bengel indicated, 4.0 has made configuring WCF services a lot easier, by providing default bindings and endpoints.

It's not clear in your question whether your web site is going to being hosting the WCF service, or simply using it (as a client), though since you're looking for the .svc file I'm leaning towards the former.

In WCF 3.5, you'll need to manually add a *.svc file as Bengel indicated in his answer. The easiest way to do this is to add a new text file, and change the extension yourself.

You'll also need to configure the binding(s) and endpoint(s) and all that other good stuff.

If you're using WCF 4.0, you don't need the *.svc file, and you can opt to use the default bindings/endpoints that WCF provides.

The service address is based on the base address of the host, and one default endpoint will be created for each unique binding/contract (so if you have two services running on NetTcp, you'll get 2 default endpoints, and if you have two services running on NetTcp and WsHttpBinding, you'll get 4 default endpoints).

You can specify values for a binding and still have it be the default binding by ommitting the name attribute.

There's a good writeup on all of this - A Developer's Introduction to Windows Communication Foundation 4 that goes into more detail with examples.

Long story short - if you're using WCF 4.0, you don't need the .svc file. If you're using WCF 3.5, you'll need to add the .svc file to your web site.

Upvotes: 1

Bengel
Bengel

Reputation: 1053

If all you need is the actual .svc endpoint all you have to do is add a new WCF Service item. Delete the extra files that come with it (usually like IService1.cs) as well as the code behind (Service1.svc.cs).

Inside the .svc file should look something like this:

<%@ ServiceHost 
Language="C#" 
Debug="true" 
Service="Service.Service1" 
CodeBehind="Service1.svc.cs" %>

Just remove the CodeBehind part and change the Service value to your own personal class. As long as your config is set up (.net 4.0 made this really simple to get working) you should be good to go!

Upvotes: 2

Related Questions