I am currently working on a project and trying to learn about WCF web services.
I have a console application which hosts a WCF service. I have added the URL that it should be accessible on in the <baseAddress> section of the App.config file. When I run the console application in debug mode in Visual Studio I get a popup saying your services have been hosted.
If I run my app outside of visual studio and go to the URL I then can’t connect, I’m guessing I need to do some configuration to make it work but can’t find what I need to do.
I have two questions, how do I get the WCF service that’s hosted within the console app to be accessible via http:// using IIS for Windows and making it available using the Mono C# with an Apache web server.
Thanks for any help you can provide.
Hosting in IIS – For Testing
To host the service in IIS, you need to create a virtual directory. There are two ways of doing this:
For easy testing:
http://yourhost/somepath/After that, your virtual directory is set up and IIS will direct all requests to
http://yourhost/somepathto your WCF Service. Note that this will point to the binaries that were generated by Visual Studio inside your project directory, so a rebuild will automatically things.This is the easiest option for development and testing, you don’t even need to have Visual Studio open, but whatever change you make will automatically be reflected to the deployed instance.
Hosting in IIS – For Production
For production, you need to create a real virtual directory. To do that:
http://yoursite/alias/and physical path simply points to the directory where you deployed your service to.Self-Hosting
Your console app is called self hosting. If this doesn’t work outside Visual Studio, then there’s usually something wrong with your
app.config. I have a simple example here.Hosting with Mono
For Mono, you have three options:
Self-hosting means creating a simple console application that’s doing some
and running that with Mono on the command-line.
See Cannot access WCF service hosted in Apache with mod-mono for how to setup apache with mod-mono, including some samples.
You also have two options here: either you copy your service into some directory that’s picked up by Apache – or you can also start
mod-mono-servermanually and specify an arbitrary directory, for instance the current one for testing.