WEBSITE

Sharepoint 2010 : Creating a Pluggable Workflow Service (part 2) - Add a SharePoint-Hosted WCF Service

11/4/2013 2:56:16 AM
Add a SharePoint-Hosted WCF Service

Now that our client WCF service is up and running, our next logical step is to implement a WCF service that can be hosted within SharePoint to receive calculation results from our client application.

  1. We’ll make use of the packaging and deployment capabilities of Visual Studio to set up our WCF service on SharePoint. In Visual Studio, choose File | New | Project and then from the New Project dialog, choose SharePoint | 2010 | Empty SharePoint Project. Name the new project WorkflowDemonstration as illustrated.

  2. Set the local site to use for debugging to the demonstration site that we created earlier: http://localhost/chapter11. We need to deploy as a farm solution since the components that we’re about to add are not supported in a sandbox.

  3. At the time of writing, no SharePoint specific template item is available for deploying a WCF service, so we have to set up the solution file manually. The first thing we need to do is to add a new WCF Service item. Press CTRL-SHIFT-A to show the Add New Item dialog. Select Visual C# | WCF Service. Name the new class CalculationResultService.cs.

  4. As before, Visual Studio will add two new files to our solution together with the appropriate references required to support WCF. Again, we’ll start off by defining our service contract. In the ICalculationResultService.cs file, enter the following:

    using System;
    using System.Runtime.Serialization;
    using System.ServiceModel;

    namespace WorkflowDemonstration
    {
    [ServiceContract]
    public interface ICalculationResultService
    {
    [OperationContract]
    bool ProcessCalculationResult(CalculationResult result);
    }

    [DataContract]
    public class CalculationResult
    {
    [DataMember(IsRequired = true)]
    public string Result { get; set; }
    [DataMember(IsRequired = true)]
    public Guid SiteId { get; set; }
    [DataMember(IsRequired = true)]
    public Guid WebId { get; set; }
    [DataMember(IsRequired = true)]
    public Guid InstanceId { get; set; }
    }
    }


  5. Since our service will ultimately send events to workflows hosted on the SharePoint workflow runtime, we have a few things to do before we can fully implement the required functionality. For now, we’ll create a stub method based on our interface. In the CalculationResultService.cs file, enter the following:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    namespace WorkflowDemonstration
    {
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirements-
    Mode.Allowed)]
    public class CalculationResultService : ICalculationResultService
    {
    public bool ProcessCalculationResult(CalculationResult result)
    {
    return true;
    }
    }
    }
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