Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Create Web Service Using Windows Application

  • Last UpdatedJun 10, 2024
  • 3 minute read

This example illustrates how to create a Web Service in a Windows application.

PROCEDURE

Dll REFERENCE

Workflow.NET.NET2  

Skelta.HWS

NAMESPACE USED

System

System.Data

System.Web

System.Web.Services

System.Web.Services.Protocols

Workflow.NET

Skelta.HWS

Skelta.Core

 

  1. In Visual Studio, open ASP.NET Web Service.

  2. Add reference "Skelta.HWS.dll" and "WorkFlow.Net.Net2.dll".

  3. Write the code in Appcode\Service.cs

    using System;

    using System.Data;

    using System.Web;

    using System.Web.Services;

    using System.Web.Services.Protocols;

    using Workflow.NET;

    using Skelta.HWS;

    using Skelta.Core;

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class Service : System.Web.Services.WebService

    {

    ApplicationObject application = null;

    WorkflowObject workflow = null;

    Actor actor = null;

    public Service ()

     {


    //Uncomment the following line if using designed components

    //InitializeComponent();

    application = new ApplicationObject("WebServiceRep");

    workflow = new WorkflowObject("WebServiceWF", application);

    }


    [WebMethod]

    public string HelloWorld()

    {

    return "Hello World";

    }


    [WebMethod]

    public DataSet GetWorkItemList(string realActorId)

    {

    WorkItemCollection workItemCollection = new WorkItemCollection(application, workflow, new

    Actor(application, realActorId), false, "WebWorkList");

    return workItemCollection.GetRecords();

    }


    [WebMethod]

    public DataSet GetWorkItemQueueList(Guid queueId, string realActorId)

    {

    WorkItemCollection workItemCollection = new WorkItemCollection(application, workflow,

    queueId, new Actor(application, realActorId));

    return workItemCollection.GetRecords();

    }


    [WebMethod]

    public void SubmitWorkItem(Guid workitemId, string statusSubmitted)

    {

    WorkItem workItem = new WorkItem(workflow, workitemId);

    workItem.Submit("WebWorkList", statusSubmitted, "", "");

    }


    [WebMethod]

    public string[] GetWorkItemOutputs(Guid workitemId)

    {

    WorkItem workItem = new WorkItem(workflow, workitemId);

    System.Collections.Generic.Dictionary<string, string>  outputs =

    ((Skelta.HWS.IHWSActivityProvider)workItem.HWSActivity.CurrentActivity.ActionHandler)

    .GetPossibleStatusList();

    string[] statusList = new string[outputs.Count];

    outputs.Keys.CopyTo(statusList, 0);

    return statusList;

    }


    [WebMethod]

    public void PickNextItem(Guid queueId, string realActorId)

    {  

    Skelta.HWS.Queue.Queue queue = new Skelta.HWS.Queue.Queue(application, queueId);

    Actor actor  = new Actor(application, realActorId);

    Skelta.HWS.WorkItem workitem = queue.GetNextItem(queueId, actor);

     

    workitem.PickItem(actor, true);

    }


    }

  4. Design a simple workflow. Publish it and associate with an event. Note that the workflow name should be the same as mentioned above.

  5. To check whether the web service you created is working or not, right-click "Service.asmx" in the Solution Explorer, and click "View in Browser".  A web page should appear.

  6. Use the web service in the Window Application Form. Create a Window Application in Visual Studio. For example, WebServiceApplication1.

  7. Design the Form. Apply the Proper Naming Convention. Add Reference of "System.web.Services."

  8. Go to Visual Studio Command Prompt.

Navigate to the Windows Application Directory in the Command Prompt. Type the following command.

wsdl /language:CS /n:"Microsoft.SqlServer.ReportingService2005"  

http://localhost:1283/SupportWf/Service.asmx?WSDL(this should be URL of the Web Service)

This step is to create a code file of the Web Service. Make use of the web service class, create an object of it and start using its methods.

  1. Type the code behind for the Form.

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;


    namespace WebServiceApplication1

    {

    public partial class Form1 : Form

    {

     SupportWF sf = new SupportWF();//creating an object of Web Service Class

     string realActorId = "skeltalist::fbb172c5-5daf-4e5d-bcff-6500b95004f1";

     Guid workitemId = Guid.Empty;

     Guid queueId = new Guid("dad821c0-eec7-464d-879c-14b76d3e4a55");

    public Form1()

    {

    InitializeComponent();

    }


    private void GetWorkItems_Click(object sender, EventArgs e)

    {

    DataSet ds = sf.GetWorkItemList(realActorId);

    workitemId = Guid.Empty;


    dataGridView1.DataSource = ds.Tables["CollectionBaseTable"];

     

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

     

    }


    void dataGridView1_RowEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)

    {

    comboBox1.Items.Clear();

    workitemId = new Guid(((DataGridView)sender).Rows[0].Cells[0].Value.ToString());

    string[] outPuts = sf.GetWorkItemOutputs(workitemId);

    foreach (string strValue in outPuts)

    {

    if (!comboBox1.Items.Contains(strValue))

    comboBox1.Items.Add(strValue);

    }

    }

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

    {


    }


    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {


    }


    private void GetQueueItems_Click(object sender, EventArgs e)

    {

    DataSet ds = sf.GetWorkItemQueueList(queueId, realActorId);

    workitemId = Guid.Empty;

    dataGridView1.DataSource = ds.Tables["CollectionBaseTable"];

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;


    comboBox1.Items.Clear();

     

    }


    private void PickQueueItem_Click(object sender, EventArgs e)

    {  

    sf.PickNextItem(queueId, realActorId);

     

    }


    private void Submit_Click(object sender, EventArgs e)

    {

    string comboBoxValue = comboBox1.Text;

    sf.SubmitWorkItem(workitemId, comboBoxValue);

    }

    }

    }

  2. Run the application. Click GetWorkItems, it will display the current item of the Workitem List. (Approval Activity).

  3. Approval Activity has two outputs, Approved or Rejected. So in the Combo Box, it will show two WorkItem tasks. Select any WorkItem Task (Approved or Rejected) and click Submit. The task gets submitted to the WorkItem.

  4. Click GetQueueItems button. The current item in the Queue will be displayed.

  5. Click PickQueueItem, select any Queue item and click PickQueueItem. It will pick the item from the Queue.

    Related Links
    TitleResults for “How to create a CRG?”Also Available in