WEBSITE

Sharepoint 2010 : Creating a Pluggable Workflow Service (part 6) - Calling a SharePoint-Hosted WCF Service

11/4/2013 3:00:25 AM

3. Calling a SharePoint-Hosted WCF Service

To complete our calculation engine implementation, we need to add some code to our DemoCalculationEngine project. We need a method that can make a call into our SharePoint WCF service to notify the workflow that calculation is complete. With the SharePoint project deployed, we first need to add a service reference to the SharePoint WCF service.

  1. In the DemoCalculationEngine project, choose Project | Add Service Reference. Set the Address to http://localhost/_layouts/WorkflowDemonstration/CalculationResultService.svc.

  2. Since the service is hosted within SharePoint, requests must be authenticated; as a result, we need to enter credentials for a user account with permissions to connect to the SharePoint site.

  3. Once the service metadata has been retrieved, set the Namespace to CalculationResultService and the click OK to complete the process.

    Note

    When adding a service reference for a SharePoint, you’ll sometimes see multiple prompts to enter credentials. Usually, after entering valid credentials once, clicking Cancel on subsequent prompts will allow the process to continue.


  4. With our service reference in place, we can move on to add the following code to handle the button click event in Form1.cs:

    private void button1_Click(object sender, System.EventArgs e)
    {
    foreach (DataGridViewRow row in dataGridView1.SelectedRows)
    {
    CalculationResultService.CalculationResultServiceClient client = new
    CalculationResultService.CalculationResultServiceClient();
    client.ClientCredentials.Windows.AllowedImpersonationLevel =
    System.Security.Principal.TokenImpersonationLevel.Impersonation;
    CalculationResultService.CalculationResult result = new
    CalculationResultService.CalculationResult();

    CalculationRequest selected = row.DataBoundItem as CalculationRequest;

    result.Result = selected.ProductName + " Complete";
    result.InstanceId = selected.InstanceId;
    result.SiteId = selected.SiteId;
    result.WebId = selected.WebId;

    if (client.ProcessCalculationResult(result))
    {
    row.Selected = false;
    _calculationList.Remove(selected);
    }
    }
    }


We can now manually trigger calculation results by selecting an item from the data grid and then clicking the Send Result button.

Tip

When hosting WCF services in SharePoint, it’s important that the client proxy allows impersonation; otherwise, some weird and wonderful COM errors may be thrown by SharePoint. To allow impersonation, set the AllowedImpersonationLevel to Impersonation, as shown in the preceding code sample.

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