WCF Service in Workflow


Introduction : The Window Communication Foundation (WCF) is service-oriented application. With the help of WCF we can send a data from one service to another. The Workflow is simply encapsulate activities for Window Communication Foundation. WCF is designed to offer a manageable approach to creating Web services and Web service clients.

Step 1 : Open Visual Studio.

  • Select File->New->Project.
  • Select WCF Workflow Service Application.
  • Click OK.
wf1.gif

After OK the following activity show.

wf``.gif
Step 2 :
Drag activity from Toolbox.

  •  Drag Flowchart activity.
wf2.gif

Step 3 : Define Variables for application.

  • Select Sequence Activity.
  • Click in Variables option.
  • Define Name, Variables Type.
wf3.gif

Step 4 : Go to Solution Explorer and right-click in project option.

  • Select Add->New Item.
  • Select Code Activity.
wf4.gif

Write down the following code:

Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.IO;
namespace DeclarativeServiceLibrary1
{
    public sealed class CodeActivity1 : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<string> Text { get; set; }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        public OutArgument<string> result { get; set; }
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            string text = context.GetValue(this.Text);
            File.AppendAllText(@"C:\WorkflowLog.txt", "Result is:" + text);
            context.SetValue(result, "Result is:" + text);
        }
    }
}


Step 5 : Go to the Design option.

  • Select ReciveRequest activity.
  • Right-click->Properties option.
  • Define operationname, ServiceContractName.
wf5.gif

Step 6 : Double-click in Flowchart.

  • Drag Switch activity, CodeActivity1 from Toolbox.
wf6.gif

Step 7 : Click on CodeActivtiy1.

  • Go to Properties option and define result and Text value.

Value :

(operat1 * operat2).ToString()

Similarly for add, subtract define a Text Value.

wf7.gif

Step 8 : Press F6 and Build the application.

Step 9 : Now we define the service path for the application.

  • Go to calculate.xamlx option.
  • Right-click ->Browse.
  • Firefox->Add option.
  • Add WcfTestClient.exe.
wf8.gif

Step 10 : Go to the Web option.

  • Select Start external program.
  • Define Web Service path.
wf10.gif

Step 11: Press F5 and run the application.

Step 12 :  Right-click in My Service Project.

  • Add Service.
wf111.gif

Step 13 : Now we click calculate option and add thee any parameter.

wf12.gif

Click in Invoke option Find the result.

wf13.gif