user2058904
user2058904

Reputation:

How To Deploy WCF To IIS And Have It Stay Alive

I've created a basic WCF service library project and deployed it to my local IIS installation (7.5). Whenever I try to navigate to it via localhost/TestWcfServiceLibrary/ I just get a directory view.

However, if I start the service in debug mode from visual studio, I get the system tray popup telling me that it's been hosted, and then when I go back to localhost/TestWcfServiceLibrary/, I'm able to see the wsdl. As soon as I stop debug mode and refresh the browser, I'm back to the directory view.

The base address in the config file is localhost/TestWcfServiceLibrary/ so I don't understand why I'm seeing this behavior.

Interestingly, if I navigate to localhost/TestWcfServiceLibrary/service.service1.svc (A file that doesn't exist) I get the wsdl even when debug mode is off.

So I have 2 questions.

1) Why does debug mode in visual studio have any affect at all on whether or not I can access the wsdl from the path localhost/TestWcfServiceLibrary ? (I suspect it's because the wcf service is not technically hosted at "localhost", it's hosted at , so the address doesn't really exist until debug mode is turned on, so I'm actually connected to the temporarily hosted version that visual studio provides and NOT the real IIS hosted webservice?)

2) When deploying a WCF service library directly to IIS, is it always correct to point to the .svc file with a the namespace and class name of your service contract, even though that file doesn't really exist (I'm guessing that's the magic that IIS performs for you)?

Upvotes: 0

Views: 167

Answers (1)

Marc Selis
Marc Selis

Reputation: 833

1) You can see where your webservice is hosted in the Web tab of the properties of your WCF project. Default behavior in VS.NET is to host your project in IISExpress, a mini IIS that comes with Visual Studio.NET and that is automatically started when you run a service. So, if you haven't changed the default then yes, your service is technically hosted at "localhost", but not on port 80 in IIS but on another port in IISExpress (The exact port varies)... I guess it's IISExpress that decides to give you the wsdl when you browse to the service address. That is not default behaviour of IIS. That will show the folder contents if directory browsing is enabled in the web.config, and otherwise gives you a 404 (not found) error.

2) There are 2 ways to activate a WCF service in IIS. Either you provide a real .svc file that lists what service implementation IIS should start. Either you indicate that in the node in your web.config file. It is the .svc part of the URL that triggers IIS to start the service.

Upvotes: 0

Related Questions