Thursday, October 24, 2013

Different Ways to Run WCF Services Locally

Today, I just wanted to post the different ways you can run a WCF service.  There are times you want to run them certain ways so here are a few to think about:


First Option:   Run it in full blown IIS

Honestly I think even though this is more work for each developer when they initially want to just run a service project the first time, rather than use IIS Express, IMO it may be worth the pain to have to set it up in full IIS locally yourself ..because IMO it's just good for devs at all levels to know IIS inside and out and many devs still do not which I think to myself why would you not want to.  

So even though now I use IISExpress, in the past I liked setting everything up in full blown IIS personally...and that's forced me to really get to know IIS and know it well through the years by doing this.  I never used Cassinni either for this reason and also it was a black box and I do not prefer black boxes.  In IIS you can solve any issue with hosting whatever, you have full control.

So doing it a more manual route to me forces you to learn IIS, because that's how you're going to deploy it anyway to other servers.  Why use something like IIS Express if that's not how you will be hosting it in a real environment, I just don't see some shortcuts as being a benefit in the case where devs are totally reliant on not knowing much of IIS at all.  For instance ASP.NET web controls and Web Forms; sure they let programmers program easily (piratically pushed us to be "dumb" programmers), but we found out years later that MVC was better and forced people to LEARN code.  I feel the same about IIS and running stuff locally.  But that's just me :).

Second Option: Run it in IIS Express

v    So to do this, in your WCF Service project, right-click your service ([MyServiceName].svc) for and choose to open it in the browser from the context menu:


This launches the service automatically in IISExpress as you will notice if you go down to the running task icons next to your clock in windows:


This also then continues to open up the service endpoint in the browser to the default service page:


Third Option:   Run the WCF project straight up using F5

This is a “WCF Service Application”.  That means by default it’s set to run in a browser and by definition of this template, has a web.config associated with it. 

So if you just want to run the service quick, by itself in memory in the background, and don’t want it to open a browser (which does NOT run the service it appears), then go to the properties of your WCF service project and tell it not to: 


By doing so, then when you set this as the default startup project, it will indeed start the service so that you can go back and my unit test above will run GREEN.

Fourth Option:   Run the WCF project straight up using F5 -  but set Project Startup Priority for the entire .NET solution

This might be better for you as you can tell it hey, I want to run my service service in memory (not through IIS) AND also run other projects like another web project, etc. in your .sln (solutoin)

To do that, just make sure that the service project is started first...as other things might rely on it such as your web project, etc.

Do this by going to the .sln properties in VS and set your startup projects and order:


Then try pressing F5, you will notice that now, the web service will run, AND for example an ASP.NET MVC project will also launch, so you have both running now.



0 comments:

Post a Comment