SharePoint 2013 Workflow – Calling a WCF Service


In SharePoint 2013 workflows, since its been re-architectured and CSOM based, the need of making Web or WCF service calls are more and we may need to deal with data and operation contracts (complex types). Hence thought of sharing samples that might help you in your implementations.

Sample Schema

The following is the schema of a sample WCF service that provides an Operation (Ensure Users) that can accept EnsureUserRequestReponse (Data Contract - Dynamic Value) as input and responds thru the same contract. The EnsureUserRequestReponse contract in turn has collection of users (Dynamic Value - Collection of Dynamic Values).

Building a Data Contract - Dynamic Value

With the help of Dynamic Value (User) and a Dynamic value collection (UserList), we need to construct another Dynamic Value (EnsureUserRequest), to represent the Data Contact.

For detailed steps on building a dynamic value and dynamic value collection, please refer to my other blog Handling Dynamic Values.

Making a WCF Service Call

Upon construction of data contract dynamic value, its time to make the WCF call. Drag drop a HTTPSend Activity and configure the following 4 properties.

Method

POST

RequestContent

EnsureUserRequest (Dynamic Value)

URL

WCF Service URL

ResponseContent

EnsureUserResponse (Dynamic Value)

 Upon completion, the activity might look similar to the following.

Retrieving WCF Response (using GetDynamicValueProperties)

The response (EnsureUserRequestResponse) from the WCF call will be stored to the dynamic variable (EnsureUserResponse) and can be retrieved thru GetDynamicValueProperties Activity.

Drag drop the GetDynamicValueProperties activity and configure the source as EnsureUserResponse.

Configure the Properties to be retrieved from the Dynamic value. In this case its Users (LHS - Name of the property on WCF service data contract) and EnsuredUserList (RHS - Local Dynamic variable)

Looping Thru Response Collection (Dynamic Value collection)

Can use a ForEach activity to loop thru the Dynamic Value collection (EnsuredUserList) and GetDynamicValueProperties activity again to read thru each Dynamic Value (Item) and get properties.

In case of nested dynamic values, we need to use GetDynamicValueProperties as well in the loop to retrieve the dynamic value at different levels.

Hope this helps you in making WCF service calls from SharePoint 2013 workflows.

Comments (1)
  1. Koen van der Linden says:

    Is the WCF webservice (default) SOAP or has is been customized to return JSON format by using WebGet attributes like: [WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]

    I tried this using the SOAP variant, but was not able to get a request hit the service.

    Changing the WCF to JSON style worked perfectly.

    Regards Koen

Comments are closed.

Skip to main content