One moment please...
 
Exact Synergy Enterprise   
 

How to: Consuming Binary and Entity web services

Introduction

Properties of entities which have large data type such as attachments, pictures, or large texts cannot be used by the entities. However, binary service allows you to view entities with large data type. This document provides a step by step guide using Microsoft Visual Studio 2010 as an example. With the samples below, you can use them for other entities with binary properties, such as:

  • ContactPerson
  • Request
  • Asset
  • Account
  • Item
  • Project
  • Resource
  • ItemCategoryProperty
  • ItemCountryDetail
  • Opportunity (this is available only for Exact Synergy Enterprise)

Other enhancements can also be made such as uploading two binary properties simultaneously.

Description

1. Open Microsoft Visual Studio 2010.

2. Create a new project with the following information:

  • Project type: Expand Visual Basic and click Windows.
  • Online Templates: Select Windows Forms Application.
  • Name: Type TestBinary at Name.

 

3. Add a service reference to the Binary service and Account service based on the following steps:

  • Click the Project menu, and then click Add Service Reference.
  • At Address, type or select a valid service URL for the binary service (for example, http://localhost/Synergy/Services/Exact.Entity.Binary.svc), and then click Go
  • At Namespace, type EntityBinary.

  • Add another service reference to the account. 
  • At Address, type or select a valid service URL for the account service (for example, http://localhost/Synergy/Services/Exact.Entity.Account.svc), and then click Go.
  • At Namespace, type EntityAccount.

4. Add the following reference for Exact Globe Next connectivity:

  • Exact.Services.Client

Note: It is not recommended to perform direct referencing to the following: Exact.Entity, Exact.Entity.Data, Exact.Entity.Service, and Exact.Utilities.EG. This is because they have been replaced with Exact.Services.Client. For more information, see How-to: Consuming entity services using entity service client proxy.

5. Open the app.config file and increase the size of maxBufferSize, maxReceivedMessageSize, and maxArrayLength. You can change the size anytime to retrieve the information successfully from the service. The default size might be insufficient for the entity service.

Initialization

1. Open Form1 class in the designer window and extend Form1 (based on the following screen). Add OpenFileDialog and SaveFileDialog controls. This interface allows you to use both Exact Synergy Enterprise and Exact Globe Next connectivity within the same application.

2. Open Form1 class in the Code Editor screen and type the following:

  • Declare variables for the binary and account objects. Since the implementation for Exact Synergy Enterprise and Exact Globe Next are different, you have to declare separate variables for both implementations.

Note: Exact Synergy Enterprise uses specific implementation and Exact Globe Next uses generic implementation for the entities.

  • Define the size for each chunk that you will be uploading.

  • Add the codes below to set the client credentials. This allows the web service to determine the person who is accessing it and whether the person has the necessary rights. Exact Synergy Enterprise requires client credentials because Exact Synergy Enterprise connects to the entity services via web service. Exact Globe Next uses components. Thus, you have to specify the Globe Database Server and Database Name whereby the system will automatically use the current Microsoft Windows user for authentication.  

 

Uploading images

Add the codes below to upload images to the account binary property.

  • The following code allows you to browse for an image.

  • Get the length of the image that you want to upload.

  • Initialize the binary service and call a "create" operation to get a new MessageID.

Note: Exact Globe Next uses the GetEGPropertyDataValue method to get the values of a particular property because the value cannot be directly accessed via the name of the value. This method loops through the properties in EntityData using Linq and returns the correct value.

  • Initialize the following variables for later use:
    • The size of the last packet of data that you will be uploading.
    • The total number of packets that you will be uploading.
    • A new variable to store each packet data.
    • The length of each data that you will be reading.

  • Break the image into chunks.

  • Upload each chunk using the binary service, and then get the next sequence number from the returned data.

  • Check the sequence number, and then increase the next packet total. Loop this process until all the packets are uploaded using the binary service.

  • Once all the images are uploaded using the binary service, assign the MessageID of the uploaded binary data to the corresponding property in the account entity. When the update or save application is called, the account entity will use the MessageID to get the image that you have uploaded and assign it to the account data.

Note: If there is more than one property which is binary, the MessageID will be post-fixed with the property name. In this example, the MessageID will be MessageIDCompanyLogo.  

In Exact Globe Next, an additional property "IsBinaryServiceEnabled" has to be added for operations that involve binary service.

Downloading images

Add the codes below to download images for the account binary property.

1. Add the following code to select a location to download the image.

2. You have to retrieve the account entity by setting the PrepareDownload property to True. Setting the PrepareDownload to True will allow the entity engine to pre-chunk the binary data that you want to download and return the corresponding MessageID. If there is more than one binary property for the message ID, the PrepareDownload property will contain the binary property. In this case, the message ID will be PrepareDownloadCompanyLogo.

3. Declare the variables to be used.

4. Call the binary service to retrieve the first chunk of the binary data, and then initialize the first chunk.

5. Create a loop when the chunk is not empty and write the chunk into the file that you have chosen earlier. Continue to use the binary service to retrieve the subsequent chunks until all the data has been retrieved and saved.

Uploading large texts

Add the codes below to upload large texts for the account binary property.

1. Convert the large text into a binary array, and then get the length of the array.

Note: Exact Synergy Enterprise must be converted using ASCII encoding and Exact Globe Next must be converted using Unicode. 

2. Initialize the binary data and call a create operation to get a new MessageID.

3. Initialize the following variables:

  • The size of the last packet of data that you will be uploading.
  • The total number of packets that you will be uploading.
  • A new variable to store each packet of data.
  • The length of each data that you will be reading.

4. Break the data into chunks.

5. Upload each chunk using the binary service, and then get the next sequence number from the returned data.

6. Check the sequence number, and then increase the next packet total. Loop this process until all the packets are uploaded using the binary service.

7. Once all the images are uploaded using the binary service, assign the MessageID of the uploaded binary data to the corresponding property in the account entity. When you call the update or save the operation, the account entity will use the MessageID to get the image that you have uploaded and assign it into the account data.

Note: If there is more than one property which is binary, the MessageID will be post-fixed with the property name. In this example, the MessageID is MessageIDRemarks.

Downloading large texts

Add the codes below to download large texts for the account binary property.

1. Retrieve the account entity by setting the PrepareDownloadRemarks property to True. This allows the entity engine to pre-chunk the binary data that you want to download and return the corresponding MessageID. If there is more than one binary property for MessageID, the PrepareDownload property will be post-fixed with the binary property. In this example, the PrepareDownload will be PrepareDownloadRemarks.

2. Call the binary service to retrieve the first chunk of binary data, and then initialize the first chunk of binary data. This is also to initialize a new byte list for later use.

3. Loop while the binary data chunk is not empty by writing the binary data chunk into the earlier chosen file. Continue to use the binary service to retrieve the subsequent binary data chunks until all the data has been retrieved and saved.

4. Convert the data from binary to text.

Note: Exact Synergy Enterprise uses Unicode and Exact Globe Next uses Unicode to convert the binary data to text.

 

Related documents

     
 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.878.569
 Assortment:  Date: 15-07-2015
 Release: 243  Attachment:
 Disclaimer

Attachments
TestBinary EXE.rar 62.3 KB Download
TestBinary.rar 52.3 KB Download