Microsoft – WCF/OData – Deploying Services to IIS


There are a couple of paths we can take towards deploying our web services.

Prerequisite – Msdeploy


I really enjoyed realizing the benefits of Microsoft MSDeploy.  It allows us to deploy to the local server and to remote hosts, as well.

Here is a list of arguments that are supported:

 Argument  Meaning
/T Simulates deployment
/Y Actual deployment
/M Destination Name of remote computer
/U Destination user name
/P Destination password
/A Authentication – NTLM/Basic

Visual Studio Publishing

We can publish from Visual Studio and here are the steps to take:

  • Launch Visual Studio
  • Load the Project
  • Access the “Solution Project”
  • Select the project, make sure to select the Project and not the Solution
  • Right click on your selection
  • And, from the drop-down menu, select “Publish…”

Publish Web Application – Profile

The first screen upon launching “Publish Web Application” is the screen pasted below:


As we do not have existing profiles, we will access the drop-down menu and select the “New” option.

Publish Web Application – Profile

In the screen below, we have chosen the name “SoftApps”; for our Profile.

publishWebApplication - NewProfile

Publish Web Application – Connections

The connection method is the most important screen.  It in we will choose the publish method, the service URL, and the Site/Application.

To just show how important it is, I burnt up a couple of hours, upon entering an incorrect “Site/application” in the screen below.

publishWebApplication - Connection - WebDeploy

The right choice for “Site/application” is:

publishWebApplication - Connection - WebDeploy (good choice)

The important distinction been that the former choice has SoftAppsWCF and the corrected choice has “Default Web Site/SoftAppsWcfService“.

IIS has a default web site known as “Default Web Site”.  And, you likely want to use that one.  On the other hand, If you are an expert IIS Administrator, you very well might have created a new web site that you want to indicate here.

Publish Web Application – Settings

The next important screen is the “Settings” screen.  In it, we choose between “debug” and “release”.

During your first iterations, I will suggest that you choose the Debug choice.

The next important decision is confirming your Database Connection Strings.  Please keep in mind that if you have the “Use this connection string at runtime (update destination web.config)” checked, you may end-up over-writing previously carefully tailored DB connection profiles on targeted hosts.

publishWebApplication - Settings

Publish Web Application – Preview

The preview screen is next.

publishWebApplication - Preview



Pasted below is the output from *.deploy.cmd:   

We unsuccessfully targeted a remote host.

wcfServiceSoftApps.deploy.cmd /T /M:WebServerRemote

SetParameters from: "WcfServiceSoftApps.SetParameters.xml"
You can change IIS Application Name, Physical path, connectionString
or other deploy parameters in the above file.
 Start executing msdeploy.exe
 "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='' -dest:auto,computerName="WebServerRemote",includeAcls="Fal
se" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disa
bleLink:CertificateExtension -setParamFile:"WcfServiceSoftApps.SetPar
ameters.xml" -whatif
Info: Using ID '2158a280-82ae-462d-9117-683b7c2aaf35' for connections to the rem
ote server.
More Information: Could not connect to the remote computer ("WebServerRemote"). On 
the remote computer, make sure that Web Deploy is installed and that the required 
process ("Web Deployment Agent Service") is started.  Learn more at:
Error: The remote server returned an error: (404) Not Found.
Error count: 1.

… due to the error code (ERROR_DESTINATION_NOT_REACHABLE), I realized I needed to do a couple of things:

  • Install & configure WebDeploy
  • Configure hosts firewall rules to allow network port connections

Msdeploy Download Matrix

I think you can go with the latest version supported by your OS.

And, for most people starting from Windows XP to Windows 2008 that will be MSDeploy version 3.

Version URL OS Version
Version 1.1 (x86) (x64) Windows 7, Windows Server 2003, Windows Server 2008, Windows Vista, Windows XP
Version 2 Windows 7, Windows Server 2003 Service Pack 2, Windows Server 2008, Windows Server 2008 R2 SP1, Windows Vista Service Pack 2, Windows XP Service Pack 3
Version 3 Windows 7 Professional, Windows Server 2003 Service Pack 2, Windows Server 2008, Windows Server 2008 R2 SP1, Windows Server 2012 Release Candidate, Windows Vista, Windows XP
Version 3.5

Download Msdeploy

Download the latest available MSDeploy for your deployment host.  As I often say, in terms of “Enterprise” Development and Deployment roadmap, Microsoft’s train is really a high speed train.  Yesterday it was called MSDeploy, Today is called WebPI, and next week it will yet be called something else.

So as I am on yesterday’s timeline, I will stay with MSdeploy and download it from

The version is v3.

As an aside and as a satire, I am trying to play music on this MS Windows 2012 box, and I do not even know how to get to MS Media Player.  So what to do, but yet again Goggle for help!

Salvation came from David Trounce:

Add Feature … User Interface and Infrastructure … Desktop Experience. This is similar to Server 2008 R2.

… Must not be my time, as still no WMPlayer.  Will just go back to Apple’e iTune, as that is installed and working.

About an hourly later, as I closed some of the multiple screens that I had left opened, discovered that I needed to restart.

This was indicated as I closed “Sever Manager”.  And, noticed the information detailed below:


That might be why no WindowsMediaPlayer.

Install Msdeploy

On the targeted host, here is a sample DOS Batch script that does the following:

  • It installs WebDeploy_2_10_x85_en-US.msi
  • The destination port is 8080 and the targeted Virtual Directory is /MSDeployAgentService2
  • And, it restarts the “Web Deployment Agent Service” (MsDepSvc)

rem msiexec /I <msi_filename> /passive ADDLOCAL=ALL LISTENURL=http://+:8080/MsDeployAgentService2/
msiexec /I WebDeploy_2_10_x86_en-US.msi /passive ADDLOCAL=ALL LISTENURL=http://+:8080/MsDeployAgentService2/

net stop msdepsvc /y
net start msdepsvc

Validate Msdeploy

Once the deployment package is prepared, test it out by issuing the *.deploy.cmd and passing in the /T command argument.

The *.deploy.cmd does a few important things:

  • It reads the *.SetParameters.xml file and one is able to change the Web Application Name, the Physical Path, and DB ConnectionString

When I issued “WcfServiceSoftApps.deploy.cmd /T” to test out my install, I get the sampled output shown below:

SetParameters from: "WcfServiceSoftApps.SetParameters.xml"
You can change IIS Application Name, Physical path, connectionString
or other deploy parameters in the above file.
 Start executing msdeploy.exe
 "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='' -dest:auto,includeAcls="False" -verb:sync -disa
bleLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateE
xtension -setParamFile:"WcfServiceSoftApps.SetParameters.xml" -whatif

Info: Adding directory (Default Web Site/SoftAppsWcfService\bin).
Info: Adding file (Default Web Site/SoftAppsWcfService\bin\EntityFramework.dll).

Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.Edm.dl
Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.OData.
Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.Servic
Info: Adding file (Default Web Site/SoftAppsWcfService\bin\Microsoft.Data.Servic
Info: Adding file (Default Web Site/SoftAppsWcfService\bin\System.Spatial.dll).
Info: Adding file (Default Web Site/SoftAppsWcfService\bin\WcfServiceSoftApps.dl
Info: Adding file (Default Web Site/SoftAppsWcfService\
Info: Adding file (Default Web Site/SoftAppsWcfService\ModelSoftApps.edmx.diagra
Info: Adding file (Default Web Site/SoftAppsWcfService\
Info: Adding file (Default Web Site/SoftAppsWcfService\packages.config).
Info: Adding file (Default Web Site/SoftAppsWcfService\Service1.svc).
Info: Adding file (Default Web Site/SoftAppsWcfService\
Info: Adding file (Default Web Site/SoftAppsWcfService\Web.config).
Info: Adding ACL's for path (Default Web Site/SoftAppsWcfService)
Info: Adding ACL's for path (Default Web Site/SoftAppsWcfService)
Total changes: 17 (15 added, 0 deleted, 2 updated, 0 parameters changed, 4302476
 bytes copied)

Actual Deploy

Actual deploy by passing in the /Y argument.  To truly deploy against a host named Sunlight we will issue:

WcfServicesSoftApps.deploy.cmd /T /M:Sunlight

IIS – Backup IIS Configuration

Backup IIS Configuration

I later found out that IIS as a capable and easily accessible tool for backing up IIS Configuration.

I will say use it before mucking up IIS too much.

Sample backup invocation

%windir%\system32\inetsrv\appcmd add backup 20131123_b4WcfInstall

List backups

%windir%\system32\inetsrv\appcmd.exe list backup

List backups

I was curious as to where backups are saved and so inquisitively goggled for where.

Thankfully did not over indulge as Mike Volodarsky’s blogged about same – Most Important AppCmd Commands: Backing up and restoring IIS7 configuration –

And, so I now that I need to do backups via appcmd and that they are stored in the C:\windows\system32\inetsrv\backup.

And, also importantly, I should occasionally back that folder up to an external storage.

IIS – Application Pool


It is possible that this is not actually needed, but I think it is best to create or identify an appropriate Application Pool.  And, then create and seed a Virtual Directory.

Create Application Pool

Before now I had stayed in the shadows of Microsoft .Net v2.  And, so I know I need a new v4.0 Application pool:


Please keep in mind that there are only two available baseline Frameworks:

  • .Net Framework v4.0.30319
  • .Net Framework v2.0.50727

I know that Windows Communication Framework was introduced in Microsoft .Net 3.5 and so I know needed the v4.0 version.

Even the lure of an accurate blog post is not enough to lure me into digging more into the difference between the Classic and Integrated Managed Pipeline Modes.  I am sure I will sooner than later run into a problem that will force me to learn.

IIS – Virtual Directory

Add a new Virtual Directory

Once you have decided on an Alias and Physical Path, please indicate as much.

But, more importantly click on the “Test Settings…”and validate your choice.


Msdeploy – Helpful Hint

Attempted MSDeploy again, by issuing “WcfServiceSoftApps.deploy.cmd /y”..

And, here is the output I received.

U:WcfServiceSoftApps.deploy.cmd /y 
SetParameters from:
You can change IIS Application Name, Physical path, connectionString
or other deploy parameters in the above file.
 Start executing msdeploy.exe
 "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package='U:\' -dest:auto,in
udeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtensi
More Information: The application pool that you are trying to use has the 'managedRuntimeVersion' property set to 'v2.

This application requires 'v4.0'.  Learn more at:
Error count: 1.

The important error informant is the line that read:

More Information: The application pool that you are trying to use has the 
'managedRuntimeVersion' property set to 'v2.
This application requires 'v4.0'.  
Learn more at:

Microsoft .Net Framework / OS Compatibility

I think it is important to note that you probably should think a bit about your development goals and weigh that against current deployment state.  That is, which WinOS version are you currently running and which .Net Frameworks does that OS Support.

For example, if you ‘re running MS Windows 2003, it does not support .Net Framework 4.5.

This is stated as much @ .NET Framework System Requirements – .NET Framework 4.5 (

.Net Framework 4.5 can only be installed on MS Windows 2008, 2008/R2, 2012, 2012/R2.

Review & Confirm your Visual Studio Project Targeted Microsoft .Net Framework

While we are it, let us quickly and briefly confirm which .Net Framework we are targeting:

  • Launch Visual Studio
  • In Visual Studio, Access “Solution Explorer”
  • Select the Project – Please be sure to choose the Project and not the Solution
  • Right click on the Project
  • From the drop-down menu, select the “Properties” entry
  • On the left side of the window, move up and select the “Application” tab
  • The “Target Framework” choices are availed, please review and confirm that this is the actual Framework you will like to target


IIS Manager – Review & Change CLR Version

Accessed IIS Manager and fumbled quite a bit with changing the targeted CLR version.

Even though I had accessed the Advanced configuration panel:


There was still no obvious path to changing the CLR Version.

Thought a bit more, and decided to change from a simple Virtual Directory to an Actual Application.

To do so:

  • Select the Virtual Directory
  • Right click on your selection and from the drop-down menu select “Convert to Application”

Select “Convert to Application” from drop-down menu


Add Application screen

Here is the initial “Add Application” screen:


Application Pool 2.0 Screen

Here is the default “Application Pool” screen:

It is obviously referencing “.Net Framework version: 2.0”.


Application Pool 4.0 Screen

Here is us changing to our preferred custom 4.0 pool.


Test Settings

Here is what our screen looks like, once we have the Application Pool that we want.


Test Settings

Please make sure to Test things out – Just click on “Test Settings…”.


Click Close.


And, once you are good “Click OK” and let us see…

Msdeploy – Good!

Attempted MSDeploy again, by issuing “WcfServiceSoftApps.deploy.cmd /y”..

And, here is the output I received.


IIS – Virtual Directory Configuration


I spent the whole day trying to get this application to work.

For those who feel the same struggle, here are screen shots from a working version.

Connection Strings




Directory Browsing


Failed Request Tracing Rules




The important configuration items to note are:

 Feature Why important?
Connection Strings Lists DB Connection items
Authentication The ones we have enabled are Anonymous / Asp.Net / Basic / Windows
Directory Browsing Enabled – To list individual files – Should be disabled once you have things working well
Failed Request Tracing Files As I said I experienced quite a bit of hardship and so resorted to this to try and see what was wrong
Logging Will talk more about this in a later post


Error: The server was unable to process the request due to an internal error.

You might get the error pasted above, if you do not add a couple of code snippets to your source code.

You need this class decoration statement:

 [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]

And, in your class initializeService method, you need:

 //very important as otherwise you will get the very unhelpful
            //The server encountered an error processing the request. 
            //See server logs for more details.
            //use Verbose Errors
            config.UseVerboseErrors = true;

Our new source code reads:

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;

namespace WcfServiceSoftApps
    //public class WcfDataServiceSoftApps : DataService
    //< /* TODO: put your data source class name here */ >
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class WcfDataServiceSoftApps : DataService< SoftAppsEntities>

        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)

                    = DataServiceProtocolVersion.V3;

            //very important as otherwise you will get the very unhelpful
            //The server encountered an error processing the request. 
            //See server logs for more details.
            //use Verbose Errors
            config.UseVerboseErrors = true;

            config.SetEntitySetAccessRule("*", EntitySetRights.All);

                                        , ServiceOperationRights.All

                            , ServiceOperationRights.All


        public IQueryable ApplicationListFetchAll()

            return this.CurrentDataSource.usp_GetApplicationList_Filtered
                      (null, null, null, null, null).AsQueryable();


        public IQueryable ApplicationListFetchFiltered
              Guid? ApplicationTypeID
            , Guid? VendorID
            , Guid? LicensingID
            , short? PlatformID
            , String SearchTag 

            return this.CurrentDataSource.usp_GetApplicationList_Filtered
                    ApplicationTypeID, VendorID, LicensingID, PlatformID, SearchTag


    } // ApplicationListFetchFiltered


IIS – Configuration – Error – 0x80070002

Once I added the debug statements, ran into a prescient error.

Web Browser - Error - HTTP Error - Compilation - Target Framework

This error pointed me to the fact that I had stipulated for .Net Framework 4.5

IIS – Configuration – Error – 0x80070002

Thought everything is well.  But, stayed in the wilderness for most of my day.  The exact error message is.

Item  Value
Error HTTP Error – 404.0 – Not Found
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002

HTTP Error 404

Web Browser - Error - HTTP Error 404.0 - Not Found


On a MS Windows 2012

Download & Install Microsoft .Net 4.5

As my installed MS Visual Studio 2012 was configured to point at Microsoft .Net 4.5 I needed to upgrade from v4.0 to v4.5.

Install it

Install it

Configure Microsoft WCF  – ServiceModelReg.exe

C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe –i

Configure Microsoft WCF Services – HTTP Activation

  • Launch Control Panel \ Programs and Features
  • Access “Windows Features”
  • In the “Select Install Type ” – Role based or Featured-based installation
  • In the “Select destination server” – Select a server from the server pool
  • In the “Feature roles” – Make sure that “.Net Framework 3.5 Features is installed” — “.Net Framework 3.5 Features” and “HTTP Activation” and “Non-HTTP Activation”
  • In the “Feature roles” – Make sure that “.Net Framework 4.5 Features is installed” — “.Net Framework 4.0/4.5 Features” and “WCF Services – HTTP Activation” / “WCF Services – TCP Activation” / “WCF Services – TCP Port Sharing”


Aforementioned, I spent a whole day trying to get this to work.  I wish that I can say that using this or that tool gave me specific error messages per MS Windows 2012.

Yes, I know that I was having “Microsoft WCF Service – HTTP Activation” problem.

As I struggled a bit and Googled for help, I found out that I should pay more attention to my targeted Framework.

But, the time wasted was more with properly provisioning WCF for .Net 4.0/4.5.  I assumed that the one for v3.5 will suffice; and had a blind spot to the need for checking the v4.0/v4.5 package(s), as well.

All problems stayed same until I goggled specifically for MS Windows 2012 & WCF.  And, found a fellow WordPresser – Steve – Host WCF in IIS8  – Windows Server 2012 ( ).

His guidance along proper configuration of Microsoft .Net v4.0 on a MS Windows 2012 finally brought me across the line.


References – IIS


References – IIS – Error Logging

References – IIS – WCF – MS Windows 2012

References – IIS – appcmd

References – Debugging WCF Services

Technical: Microsoft – SQL Server / Internet Information Server (IIS) – OData – Service – Error Logging

Technical: Microsoft – SQL Server / Internet Information Server (IIS) – OData – Service – Error Logging


As a follow-up to Technical: Microsoft – SQL Server / Internet Information Server (IIS) – OData – Service ( ) , let us discuss error logging.


The impetus to explicitly address error logging was seeded by this error message:

Screen Shot



The server encountered an error processing the request. See server logs for more 

Launch Visual Studio

Launch Visual Studio and load our project.

WCF Configuration

In Solution Explorer, right click on the Application’s Configuration file.  Note that if this is a Web Project the name of the configuration file will be web.config and if it a Console Application, it will be named App.config.

Please be sure to choose the generic configuration file.  In the case of a web project, choose web.config file and not the web.debug.config nor the web.release.config.

Once you right click on App’s Config file, a drop-down menu will appear.  From the drop-down menu an entry labelled “Edit WCF Configuration” will be visible.

If the “Edit WCF Configuration” menu item is not present, access the main  menu and click on the menu items “Tool”\WCF Service Configuration Editor”.  Exit the ensuring “WCF Service Configuration Editor” as changes made here are disjointed from our App’s Configuration.  Return to the App Configuration and click on the now visible “Edit WCF Configuration”.

WCF Configuration Choices


Access the Diagnostics section and use the provided hyperlinks 

  • WMI Provider (checked)
  • Log Auto Flush (checked)
  • MessageLogging  (checked)
  • Tracing (checked)
  • Trace Level – Warning \ Activity Tracing (checked)

Diagnostics – Message Logging

  • LogEntireMessage (checked)
  • LogKnownPii (checked)
  • LogMalformedMessages (checked)
  • LogMessagesAtServiceLevel (checked)
  • LogMessageaAtTransportLevel (checked)


OS Folder & File Level Permissions

Depending on the folder where the Log File will be kept, please ensure that the Account that your Web Pool is running has OS Level folder permissions to that folder.

Review Log File

Conventionally, the log file’s extension is svclog.  And, the OS is configured to rely on the Microsoft Trace File Viewer to view changes being logged in that file.

To launch “Trace File Viewer” access Windows Explorer and sojourn to your Log Folder, select your log file, and choose to view using the aforementioned utility.

Sample Errors

Sample Errors – Error EntitySet Name

I intentionally entered the wrong “Entity Set” name:

config.SetEntitySetAccessRule("xclients", EntitySetRights.AllRead);

Note that the our entity set name is clients and not xclients.

Error Message

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.ArgumentException: The given name 'xclients' was notfound in the entity sets.

Parameter name: name

Screen Shot:

Editor Error Messages

During the course of using the GUI to effect configuration changes, we ran into an error stating:

propagateActivity is a duplicate name

The only way we were able to get a bit ahead of that logjam was to use an editor (notepad++ for me) and remove wholesale the configuration section area of our configuration file (web.config) and reload the uncluttered file.

Please be sure to effect this change in the generic web.config file and not the web.debug.config nor the web.release.config.