Pages

Tuesday, December 9, 2014

How to Develop and Deploy WCF REST Servvice Web Deployment Manager / Jenkins

The following steps needs to be followed to deploy the WCF REST service in IIS using the Web Deployment Manager and Jenkin. They are

1. Download and Install Web Platform Installer

2.  Open the Microsoft Web Platform Installer and Install the following components to execute the MSBuild targets and also deploy the web application in IIS through Web Deployment Manager.

  2.1 Microsoft.Net Framework 4.5

     This component is required for to install the SharpDevelop IDE and also Run time environment for the IIS. 

  2.2 Web Deployment Manager

   This component is required for to deploy the REST FULL Web Services through Remote

  2.3 Visual Studio 2010 Shell (Isolated)

This component is required for to deploy the REST FULL Web Services using MSBuild targets. For example  /p:DeployOnBuild=True

3. Install the IIS 

This step is only required if your not installed IIS in Windows 7. I have highlighted the required component in bold font. Open the Control Panel --> Programs and Features -->  Turn Windows Feature On or Off --> Select Internet Information Services and Click OK Button. It will install the IIS.

  3.1 Enabling the AST..Net Handler

   This component is required to enable the ASP.net Mapping Handler components in IIS. This component was not installed after installing the IIS.  Open the Control Panel --> Programs and Features -->  Turn Windows Feature On or Off --> Select Internet Information Services --> Select World Wide Web Services --> Select ASP.NET check box and Click OK Button. It will install the ASP.NET feature.

  3.2 Enabling the WCF Handler

   This component is required to enable the WCF Mapping Handler  components in IIS. This component was not installed after installing the IIS.  Open the Control Panel --> Programs and Features -->  Turn Windows Feature On or Off --> Select Microsoft .NET Framework 3.5.1  --> Select Windows Communication Foundation HTTP Activation and  Windows Communication Foundation Non-HTTP Activation  and Click OK Button. It will install the WCF feature.

4. Download and install the Sharpdevelop IDE

 

5. Create the REST Service Project Using the Sharpdevelop IDE

Open the SharpDeveop IDE --> File --> Solution --> C# --> WCF -->  Select WCF REST Service and Enter Name is RestDemoService and Click Create Button and It will create the WCF REST Service Project. My Sample Code is given below. I am deploying the default generated code rest full wcf servce using web deployment manager and jenkin job.


using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace RestDemoService
{
    [ServiceContract]
    public interface IService
    {
       [OperationContract]
       [WebGet(UriTemplate = "operation/{name}")]
       string MyOperation(string name);
    }
  
    public class Service : IService
    {
       public string MyOperation(string name)
       {
          // implement the operation
          return string.Format("Operation name: {0}", name);
       }
    }
}


6. Include the Visual Studio MSBuild Targets

 By default sharpdevlop ide was included the visual studio web application msbbuild targets. These msbuild targets are required to package the rest full wcf service as a zip file and also publish the zip files into the IIS Web Site.

Open the RestDemoService.csproj file and import the Microsoft.WebApplication.targets file. 
 
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

My windows 7 operating system is 32 bit machine and I have installed the  Visual Studio 2010 Shell 32 bit version. If your installed 64 bit version choose the path MSBuildExtensionsPath64. The sample 64 bit version as follows:

<Import Project="$(MSBuildExtensionsPath64)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />


  Include the .svc and .config file in the Package


   By default .svc and .config files are not included in the package. We need to modify the .csproj file 

Original Version:

<ItemGroup>
    <None Include="Service.svc" />
    <None Include="web.config" />
  </ItemGroup>

Modified Version:

 <ItemGroup>
    <Content Include="Service.svc" />
    <Content Include="web.config" />
  </ItemGroup>

7. Check in the Code into your repository. 

My sample repository is svn.

8. Download the Jenkins and Install


9. Configuring the MSBuild .Net Plugin


Open the Jenkin Console and Click Manage Jenkins --> Manage Plugins --> Available  --> Select MsBuild Plugin -->Click Install Without Restart Button. It will install the MSBuild .Net Plugin

10.  Configuring the MSBuild Compiler

Open the Jenkin Console and Click Manage Jenkins --> Configure System --> Add MSBuild  -->Enter the following details.

MSBuild Name: MsBuild - 4.0
Path to MSBuild: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

In my example i am using the .net framework 4.0 and I have entered the msbuild .net 4.0 as shown above.

Click Save and It will save the MSBuild Configuration.

11.  Creating the Jenkin Job


Open the Jenkin Console --> Click New Item and Enter the following details to create the Jenkin Job:

1. Enter Item Name: Rest Demo Service
2. Select Freestyle project.

Click OK Button and It will create the Jenkin Job.


12. Configuring the Source Control

Open the Jenkin Console --> Click Jenknin job Rest Demo Service -> Configure --> Select Subversion in the Source Code Management and Enter the Repository URL. After entering the URL and It will ask the Credentials. Please click the Credentials and it will authenticate the user against the SVN Authentication repository. Leave the rest of the options as it is and Click Save Button and It will configure the subversion.

13.  Triggering the Build

Open the Jenkin Console --> Click Jenknin job Rest Demo Service -> Select Poll SCM and Enter the Schedule Time. My Sample build needs to be run every 11 Hours once. I have configured as follows:

H 11 * * *

14. Configuring the Build

Open the Jenkin Console --> Click Jenknin job Rest Demo Service -> Enter the following details:

1. MSBuild Version:

    This msbuild version is already configured in the configure system. Please select the MSBuild Version in the Combo box. In My case MSBuild Version is MSBuild - 4.0

2. MSBuild Build File:

   Enter the Solution File or Project File. In my example Solution File Name is RestDemoService.sln

3. Command Line Arguments:


/t:clean /t:rebuild /p:Configuration=Debug /p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:MSDeployPublishMethod=RemoteAgent /p:CreatePackageOnPublish=True /p:DeployIisAppPath="Default Web Site/RestDemoService" /p:MsDeployServiceUrl=<Remote Agent Host Name>  /p:username="Administrator User Name" /p:password=<Admin Password> 

I am deploying the application in Default Web Site/RestDemoService. You can replace with your Web Site/Application Name.

Deploying the Application Remote Server

MSDeployPublishMethod = RemoteAgent
MsDeployServiceUrl = Remote Host Name


Deploying the Application Local Machine

 MSDeployPublishMethod = InProc


username=Administrator User Name
password=Administrator Password



The above command will clean the build, compile the build and package as a zip file and publish to the IIS using the Deployment Manager using msbuild.


15. Running the Jenkin Job

Open the Jenkin Console --> Click Jenknin job Rest Demo Service -> Click Build Now. It will build the web application and deploy web application into the IIS.


16. Testing the WCF REST Service


Open the Browser and Access the following URL to test the WCF Web Service:

http://localhost/RestDemoService/Service.svc/operation/add

Response:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Operation name: add</string>