One moment please...
 
Exact Globe+   
 

How-to: Consuming entity services using entity service client proxy

Introduction

The entity services of Exact Globe Next allow you to perform the "Create", "Retrieve", "Update", "Delete", "OpenNew", "Validate", and "Save" (CRUDOVS) functions with third party applications. This document provides a step-by-step guide using Microsoft Visual Studio 2012 as an example.

This document demonstrates:

  1. How to create an application that consumes the Entity services
  2. Through the Exact Entity Services Client proxy, Exact.Services.Client
  3. To perform CRUDOVS actions on a Resource entity

Description

  1. Open Microsoft Visual Studio 2012.
  2. Create a project with the following information:
    • .NET Framework 4
    • Installed\Templates\Other Languages\Visual Basic\Windows\Windows Form Application
    • Name: EntityTestApplication


 

  1. Add references in order to consume Entity services:
    • Right-click the EntityTestApplication project, and then click Properties.
    • Click References. In the References screen, click on Add… to add a reference.
    • Add the following references to the application. You can find these files under the bin sub-folder of the Exact Globe Next installation folder:
      • Exact.Services.Client.dll
    • Add the following system references to the application:
      • System.Runtime.Serialization


 

  1. Open the Form1 class in the Designer window.

    Add the following controls to Form1:
    • Eight button controls (Button 1 to Button 7)
    • Nine label controls (Label 1 to Label 9)
    • Eight text box controls (TextBox1 to TextBox8)


 

  1. Copy the following code into Form1.vb. The Resource entity will be used in this example.  

Public Class Form1

    Private Enum Actions
        Create
        Retrieve
        Update
        Delete
        OpenNew
        Validate
        Save
    End Enum

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "Resource Entity example" 

        'Assign controls label
        Button1.Text = "Create" : Button2.Text = "Retrieve"
        Button3.Text = "Update" : Button4.Text = "Delete"
        Button5.Text = "OpenNew" : Button6.Text = "Validate"
        Button7.Text = "Save"

        Label1.Text = "Resource ID" : Label2.Text = "Last Name"
        Label3.Text = "User ID" : Label4.Text = "Full Name"
        Label5.Text = "Employment Start Date"
        Label6.Text = "Server" : Label7.Text = "Database"
        Label8.Text = URL:Port
        Label9.Text = "http://<server>:Port/Services"

        ' Enter default URL, Server and Database settings here.
        TextBox8.Text = "http://change_me:8010/services"
        TextBox6.Text = "change_me"
        TextBox7.Text = "001" 
    End Sub

    ''' <summary>
    ''' Create record action
    ''' </summary>
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        DoAction(Actions.Create)
    End Sub 

    ''' <summary>
    ''' Retrieve record action
    ''' </summary>
    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        DoAction(Actions.Retrieve)
    End Sub 

    ''' <summary>
    ''' Update record action
    ''' </summary>
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        DoAction(Actions.Update)
    End Sub 

    ''' <summary>
    ''' Delete record action
    ''' </summary>
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        DoAction(Actions.Delete)
    End Sub 

    ''' <summary>
    ''' Open new record action
    ''' </summary>
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        DoAction(Actions.OpenNew)
    End Sub 

    ''' <summary>
    ''' Validate record action
    ''' </summary>
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        DoAction(Actions.Validate)
    End Sub 

    ''' <summary>
    ''' Save record action
    ''' </summary>
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        DoAction(Actions.Save)
    End Sub 

    ''' <summary>
    ''' Helper function to assign Text fields value to EntityData
    ''' </summary>
    Private Function GetFormData() As Exact.Services.Client.Data.EntityData
        Dim Data As New Exact.Services.Client.Data.EntityData

        Data.EntityName = "Resource" 

        If Not String.IsNullOrWhiteSpace(TextBox1.Text) Then
            Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
                                With {.Name = "ID", .Value = TextBox1.Text})
        End If

        Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
                            With {.Name = "LastName", .Value = TextBox2.Text})
        Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
                            With {.Name = "UserID", .Value = TextBox3.Text})
        Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
                            With {.Name = "FullName", .Value = TextBox4.Text}) 

        If Not String.IsNullOrWhiteSpace(TextBox5.Text) Then
            Data.Properties.Add(New Exact.Services.Client.Data.PropertyData _
                                With {.Name = "EmploymentStartDate", .Value = TextBox5.Text})
        End If 

        Return Data
    End Function

    ''' <summary>
    ''' Helper function to assign EntityData to Text fields
    ''' </summary>
    Private Sub FillData(ByVal Data As Exact.Services.Client.Data.EntityData)

        TextBox1.Text = Data.Properties("ID").Value
        TextBox2.Text = Data.Properties("LastName").Value
        TextBox3.Text = Data.Properties("UserID").Value
        TextBox4.Text = Data.Properties("FullName").Value
        TextBox5.Text = Data.Properties("EmploymentStartDate").Value
    End Sub

    ''' <summary>
    ''' To perform CRUDOVS action using entityClient object
    ''' 1. Crate entityClient object
    ''' 2. Assigning all user input into EntityData by calling the function GetFormData()
    ''' 3. Pass EntityData object (from GetFormData()) to the entityClient CRUDOVS methods. 
    ''' 4. Fill returned data from entityClient CRUDOVS methods by FillData() method.(Only if CRUDOVS methods is not a Sub method.
    ''' </summary>
    Private Sub DoAction(action As Actions)

        Try
            Dim entityClient As New Exact.Services.Client.Entity.EntityClientEG(TextBox8.Text, TextBox6.Text, TextBox7.Text)

            Select Case action
                Case Actions.Create : FillData(entityClient.Create(GetFormData()))
                Case Actions.Delete : entityClient.Delete(GetFormData())
                Case Actions.OpenNew : FillData(entityClient.OpenNew(GetFormData()))
                Case Actions.Retrieve : FillData(entityClient.Retrieve(GetFormData()))
                Case Actions.Save : FillData(entityClient.Save(GetFormData()))
                Case Actions.Update : entityClient.Update(GetFormData())
                Case Actions.Validate : FillData(entityClient.Validate(GetFormData()))
            End Select 

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

  1. Run the application. Define the relevant information at URL:Port, Server, and Database and click the necessary action button.

This example can be found as an attachment in this document.

Related document

  • Exact video library
  •      
     Main Category: Support Product Know How  Document Type: Online help main
     Category: On-line help files  Security  level: All - 0
     Sub category: General  Document ID: 19.530.659
     Assortment:  Date: 26-09-2022
     Release: 394  Attachment:
     Disclaimer

    Attachments
    EntityTestApplication.zip 124.6 KB Download