WEBSITE

Sharepoint 2010 : Creating a Pluggable Workflow Service (part 3) - Hosting an .svc File in SharePoint, Token Replacement in Visual Studio , Adding WCF Service Configuration to SharePoint

11/4/2013 2:57:08 AM
Hosting an .svc File in SharePoint

To make our service available for our client application, we need to host it somewhere. Since SharePoint runs on Internet Information Server (IIS), we need to create a .svc file with details of our service implementation. Of course, before we create the file, we need somewhere to put it; for the purposes of this demonstration, we’ll use a custom subfolder within the %SPROOT%\TEMPLATE\Layouts folder. We can set up this folder automatically using our Visual Studio project.

  1. Choose Project | Add SharePoint “Layouts” Mapped Folder. You’ll notice that a new Layouts folder is added to the solution:

  2. We can now go ahead and add our CalculationResultService.svc file. In the Layouts\WorkflowDemonstration folder, add a new XML file named CalculationResultService.svc. Replace the contents of the file with the following:

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$"%>
    <% @ServiceHost Service="WorkflowDemonstration.CalculationResultService" %>
Token Replacement in Visual Studio

Visual Studio 2010 allows the use of replaceable tokens when creating SharePoint solution packages. Our code sample makes use of the token $SharePoint.Project.AssemblyFullName$ that will be replaced when the package is built, by the four-part assembly name for the associated assembly. However, at the time of writing, no WCF template is available for SharePoint. Therefore, tokens are not automatically replaced in files with an .svc extension.

Thankfully, this is a simple problem to resolve. Navigate to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\SharePointTools and then open the Microsoft.VisualStudio.SharePoint.targets file. This is an XML format file that defines various configuration settings for building SharePoint projects. Find the TokenReplacementFileExtensions element and append svc to the list of file extensions as shown:

<TokenReplacementFileExtensions>$(TokenReplacementFileExtensions);xml;aspx;ascx;
webpart;dwp;svc </TokenReplacementFileExtensions>



Adding WCF Service Configuration to SharePoint

As well as an .svc file, IIS also needs to read the configuration of the WCF service from the web.config file. For the purposes of our demonstration, we’ll make the necessary changes manually.

  1. Open the web.config file for our application (at C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config if the application is the first application running on port 80). In the system.serviceModel element, add the following configuration details:

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <bindings>
    <basicHttpBinding>
    <binding name="WfDemoBinding">
    <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" />
    </security>
    </binding>
    </basicHttpBinding>
    </bindings>
    <behaviors>
    <serviceBehaviors>
    <behavior name="WfDemoBehavior">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    </serviceBehaviors>
    </behaviors>
    <services>
    <service behaviorConfiguration="WfDemoBehavior"
    name="WorkflowDemonstration.CalculationResultService">
    <endpoint address="" binding="basicHttpBinding"
    bindingConfiguration="WfDemoBinding"
    contract="WorkflowDemonstration.ICalculationResultService">
    <identity>
    <dns value="localhost" />
    </identity>
    </endpoint>
    <host>
    <baseAddresses>
    <add baseAddress="http://localhost/_layouts/WorkflowDemonstration" />
    </baseAddresses>
    </host>
    </service>
    </services>


We’re now ready to deploy the service to SharePoint. From the Build menu select Deploy WorkflowDemonstration. Visual Studio will now build the solution, create a WSP package, and then deploy the package to our SharePoint server.

As we did for our client application, we can now make use of WCFTestClient to send a test call to our WCF service. This time the endpoint address will be http://localhost/_layouts/WorkflowDemonstration/CalculationResultService.svc. If all is well, our service will return True when invoked as per our stub implementation.

Other  
  •  PowerShell for SharePoint 2013 : Word Automation Services - Disable Word 97–2003 Document Scanning , Disable Embedded Fonts in Conversions
  •  PowerShell for SharePoint 2013 : Word Automation Services - Modify Job Monitoring, Modify Conversion Timeouts
  •  PowerShell for SharePoint 2013 : Word Automation Services - Configure Supported Document Formats for Conversion, Modify Database Information
  •  PowerShell for SharePoint 2013 : Word Automation Services - Configure the Conversion Processes, Configure Conversion Throughput
  •  ASP.NET 4 : Error Handling, Logging, and Tracing - Throwing Your Own Exceptions
  •  ASP.NET 4 : Error Handling, Logging, and Tracing - Handling Exceptions
  •  ASP.NET 4 : Error Handling, Logging, and Tracing - Exception Handling
  •  ASP.NET 4 : Error Handling, Logging, and Tracing - Common Errors
  •  Sharepoint 2010 : Designing a Workflow Using Visio 2010 (part 3) - Using Visio Services to Visualize Workflow State
  •  Sharepoint 2010 : Designing a Workflow Using Visio 2010 (part 2) - Implementing a Visio Workflow Using SharePoint Designer
  •  
    Top 10
    Review : Sigma 24mm f/1.4 DG HSM Art
    Review : Canon EF11-24mm f/4L USM
    Review : Creative Sound Blaster Roar 2
    Review : Philips Fidelio M2L
    Review : Alienware 17 - Dell's Alienware laptops
    Review Smartwatch : Wellograph
    Review : Xiaomi Redmi 2
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8