Click here to Skip to main content
15,885,985 members
Articles / Web Development / ASP.NET

Convert WCF Service from Visual Web Developer Express to IIS Express using Web Matrix

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
16 Dec 2012CPOL4 min read 13.4K   4   5   1
An easy guide to run a web service in a more real environment using free tools from Microsoft.

Introduction

When you have developed a WCF web service using the internal Visual Studio Development Server, you should test it in a more real environment. They say IIS Express is a good choice in this case.

There are several articles/tutorials how to do that using Visual Studio graphical tools and/or full IIS Manager, listed in the additional sources below. This short article is about how to do this if you just have Microsoft Visual Web Developer Express Edition and IIS Express without those graphical tools. The free Microsoft Web Matrix 2.0 will be used for controlling IIS Express instead.

The VWD Express version in question is 2008, but 2010 should be similar. IIS Express version is 7.5. 

Additional sources: 

  1. http://msdn.microsoft.com/cs-cz/library/ms733766.aspx
  2. http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx
  3. http://www.youtube.com/watch?v=mX8quq7MoeI

Using the code

There is a sample Visual Web Developer Express 2008 project attached. It runs the sample generated WCF web service at Microsoft Visual Studio Development Server.

Next, there is its conversion to Web Matrix 2.0 website that runs the same web service using IIS 7.5 Express.

Step 1 – Prerequisites

It’s supposed you have a working WCF service. A way to test it is to run it (see picture 01).

Image 1

Copy the address from your browser’s address bar (it opens automatically), start a Visual Studio 2008 Command Prompt (it comes with Visual Studio and sets the path for using additional tools) and type:

wcftestclient http://localhost:nnnn/YourService.svc (an address from the browser).

In a graphical tool (see picture 02) you should see a tree of contract(s) containing the web service operation(s). You can doubleclick an operation, set its input parameters (if any) and Invoke it to see if it returns what you expect. 

Image 2 

Step 2 – Install IIS 7.5 Express and Microsoft Web Matrix 2.0 

It can be accomplished in one single step by downloading the installer from http://www.microsoft.com/web/webmatrix/

Step 3 – Set the endpoint (optional)

In your VWD Express open your web.config file and modify the binding for your endpoint(s) to basicHttpBinding. This is a suggested step for older target IIS compatibility according to the additional source 3) and might be omitted. If you are not sure, modify the behaviorConfiguration in your web config as follows:

XML
<service behaviorConfiguration="YourService.YourServiceBehavior"
name="YourServiceNamespace.YourService"> 
    <endpoint address="basic" binding="basicHttpBinding"
    contract="YourServiceNamespace.IYourServiceContract">
        <identity> 
            <dns value="localhost" />
        </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

After the change, you can rebuild the VWD Express project and retest the web service functionality (see Step 1).

Step 4 – Convert the project to Web Matrix 2.0 

Don’t use the newly added context menu item  „Open as a Web Site with Microsoft WebMatrix“, which is shown at folders in the Windows Explorer. It would make your following work more complicated.

Image 3 

Instead, start Web Matrix 2.0 directly, click „Templates“, „Empty web“ and set its name as desired.

After the Web Matrix 2.0 GUI has been shown, you can test whether the IIS 7.5 Express works correctly. In a Homepage tab, run the web in your browser and see your system tray if it indicates the IIS start, see picture 04.

Image 4 

Copy the YourService.svc file into the project root.

Replace the Web.config in the root by your modified Web.config from Step 3.

Create the folder App_Code at the same level as App_Data (i.e. in the root). Copy your codebehind file YourService.svc.cs and contract file IYourService.cs to that folder.

Image 5 

Step 5 – Modify the project in the Web Matrix 2.0 

Remove the codebehind reference from YourService.svc markup.

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

Don’t be confused if Web Matrix underlines the markup in red as incorrect. It works.

If your WVD project was .NET 3.5, you will need to comment out some lines in your web.config because WebMatrix runs the code on .NET 4.0. You will find out, when you restart your modified site and view it in your web browser. If there are corresponding errors listed, modify your web.config as follows.

XML
<configSections>
<sectionGroup name="system.web.extensions"
 type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
 System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=AAAABBBBCCCCDDDD">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=AAAABBBBCCCCDDDD">

<!--<section name="scriptResourceHandler"
type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,PublicKeyToken=AAAABBBBCCCCDDDD"
requirePermission="false" allowDefinition="MachineToApplication"/>-->

<sectionGroup name="webServices" type="System.Web.Configuration.
ScriptingWebServicesSectionGroup, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=AAAABBBBCCCCDDDD">

<!--<section name="jsonSerialization"
type="System.Web.Configuration. ScriptingJsonSerializationSection,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=AAAABBBBCCCCDDDD" requirePermission="false" allowDefinition="Everywhere"/>-->

<!--<section name="profileService" type="System.Web.Configuration
.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=AAAABBBBCCCCDDDD" requirePermission="false"
allowDefinition="MachineToApplication"/>-->

<!--<section name="authenticationService"
type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=AAAABBBBCCCCDDDD" requirePermission="false"
allowDefinition="MachineToApplication"/>-->

<!--<section name="roleService"
type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=AAAABBBBCCCCDDDD" requirePermission="false"
allowDefinition="MachineToApplication"/>-->  

</sectionGroup> 
</sectionGroup>
</sectionGroup>
</configSections>

After that, your website should show blank page without any error.  

Step 6 – Access your webservice, now running at IIS 7.5 Express

Ensure that Visual Development server is stopped.

Image 6 

You can do that also by closing Visual Web Developer Express. 

Restart your site in WebMatrix 2.0 and run it in your favourite browser. In the address line, there should be <a>http://localhost:nnnn</a>. Append it with /YourService.svc and press Enter.

The web service welcome screen should be shown – the same you can see when it is running under Microsoft Visual Studio Development Server from VWD Express. But now it runs on IIS 7.5 Express. Congratulations.

Image 7 

Step 7 – Retest your webservice hosted at  IIS 7.5 Express

Start WCF test client (see Step 1) and try to invoke web service operations if they work as expected.

Notes

When running IIS 7.5 Express I sometimes encounter Internet Connection unavailable error. This can usually be fixed by restarting your website. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Czech Republic Czech Republic
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThanks Pin
Dishant Verma14-Jan-15 6:02
Dishant Verma14-Jan-15 6:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.