Sample Code (Visual Studio or REACT.js)

xAIgent is a RESTful service designed to work with any Integrated Development Environment (IDE) that supports RESTful services.

The following discussion illustrates how to incorporate the xAIgent service into a Visual Studio or REACT.js project. NOTE: the sample code presented here is taken from sample projects that are available for download. Please see the download section at the bottom of this page.

Visual Studio

1. Add the service to the project.

In the Solution Explorer, right mouse click on the References node.

Select Add Service Reference...

In the Address: enter the address of the xAIgent wsdl (Web Services Description Language) file.

Change the default namespace to xAIgentService ...

and press the OK button. Visual Studio will now add the service reference and generate the necessary handlers.

2. Once the service has been added to the project you can now program against the service using its request and response classes. NOTE: The xAIgent Service exposes two methods for the developer:

GetExtraction - The following discussion illustrates how to incorporate the xAIgent service in to a Visual Studio project. PLEASE NOTE: The sample code presented here is taken from the sample projects available for download at the bottom of this page.

GetTokenStatus - Requires a TokenStatusRequest object and Returns a TokenStatusResult object. For more information on the GetTokenStatus method please review the sample application download below.

The following code is taken from the sample application available for download below that submits text from a text box and parses the response in to a second text box ...

C Sharp sample:

//Create an instance of the xAIgent restful service

xAIgentService.DBIXServiceClient myxAIgentService = new xAIgentService.DBIXServiceClient();

//Create an instance of the xAIgent request

xAIgentService.ExtractionRequest myxAIgentRequest = new xAIgentService.ExtractionRequest();

//Create an instance of the xAIgent result

xAIgentService.ExtractionResult myxAIgentResponse = new xAIgentService.ExtractionResult();

//Set the application ID to identify the application calling the xAIgent service

myxAIgentRequest.ApplicationID = "xAIgent C# sample";

//Set the language for the document to be extracted to Auto Detect. NOTE: This does not work with Japanese or Korean

myxAIgentRequest.LanguageID = 0;

box try


//Run the xAIgent Service to extract the text and return the key phrases.

myxAIgentResponse = myxAIgentService.GetExtraction(myxAIgentRequest);

int myResultsCounter = 1;

this.TextBoxResults.Text = "";

if (myxAIgentResponse.KeyPhrases.Count() > 0)


//Process each key phrase object in the response.

foreach (xAIgentService.KeyPhrase keyPhrase2Process in myxAIgentResponse.KeyPhrases)


keyPhrase2Process.Phrase = keyPhrase2Process.Phrase.ToUpper();

keyPhrase2Process.Highlight = keyPhrase2Process.Highlight;

//Output the keyphrase object to the results text box.

this.TextBoxResults.Text = this.TextBoxResults.Text + myResultsCounter.ToString() + ". " + keyPhrase2Process.Phrase + System.Environment.NewLine + _

"Score: " + keyPhrase2Process.Score.ToString() + System.Environment.NewLine + _

"Highlight: " + keyPhrase2Process.Highlight + System.Environment.NewLine + System.Environment.NewLine;

myResultsCounter = myResultsCounter + 1;




this.TextBoxResults.Text = "No Results were returned.";


catch (Exception ex)


this.TextBoxResults.Text = ex.Message.ToString();


VB.NET sample:

Dim myxAIgentService As New xAIgentService.DBIXServiceClient 'Create an instance of the xAIgent restful service
Dim myxAIgentRequest As New xAIgentService.ExtractionRequest 'Create an instance of the xAIgent request
Dim myxAIgentResponse As New xAIgentService.ExtractionResult 'Create an instance of the xAIgent result
myxAIgentRequest.ApplicationID = "xAIgent VB.NET sample" 'Set the application ID to identify the application calling the xAIgent service
myxAIgentRequest.LanguageID = 0 'Set the language for the document to be extracted to Auto Detect. NOTE: This does not work with Japanese or Korean

myxAIgentRequest.NumberOfPhrasesToReturn = 5 'Set the number of phrases to return

myxAIgentRequest.SubscriptionID = "Your Subscription ID" 'Set the Subscription ID for authentication to use the xAIgent service

myxAIgentRequest.XTractionDocument = Me.TextBoxExtractee.Text 'Set the document for extraction to the text in the TextBoxExtractee text box

myxAIgentResponse = myxAIgentService.GetExtraction(myxAIgentRequest) 'Run the xAIgent Service to extract the text and return the key phrases.

Dim myResultsCounter As Integer = 1

Me.TextBoxResults.Text = ""

If myxAIgentResponse.KeyPhrases.Count > 0 Then

'Process each key phrase object in the response.

Dim keyPhrase2Process As xAIgentService.KeyPhrase

For Each keyPhrase2Process In myxAIgentResponse.KeyPhrases

keyPhrase2Process.Phrase = keyPhrase2Process.Phrase.ToUpper

keyPhrase2Process.Highlight = keyPhrase2Process.Highlight.ToCharArray()

'Output the keyphrase object to the results text box.

Me.TextBoxResults.Text = Me.TextBoxResults.Text & myResultsCounter.ToString & ". " & keyPhrase2Process.Phrase & vbCrLf & _

"Score: " & keyPhrase2Process.Score.ToString & vbCrLf & _

"Highlight: " & keyPhrase2Process.Highlight & vbCrLf & vbCrLf

myResultsCounter = myResultsCounter + 1



Me.TextBoxResults.Text = "No Results were returned."
End If

Catch ex As Exception

Me.TextBoxResults.Text = ex.Message.ToString()

End Try

React js Sample:

A React implementation of the xAIgent service requires the creation of a Restful Service wrapper that Java based environments can consume as Request/Response. In the sample below, the xAIgent has been interfaced using an ASP.NET MVC implementation of the xAIgent to a Restful presentation of the Service … dbiXServiceAPI. The dbiXServiceAPI source code can be found in the React js source code download below in the “dbiXserviceAPI Source.docx file”. For more information on enabling Web API for empty projects, visit

NOTE: The ASP.MVC implementation is not the only way to implement a SOAP service in to Java, alternatively the developer may choose to generate JavaScript code from the xAIgent WSDL file, and then use that generated code in your React.js application.

dbiXserviceAPI source file

using dbiXServiceAPI.Request;
using dbiXServiceAPI.Response;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualBasic;
namespace dbiXServiceAPI.Controllers



public class AppDemoController : ControllerBase

private int AuthCode { get; set; }
// Hook to the dbiXServiceAPI that wraps the xAIgent service
private xAIEngine.DBIXServiceClient myXAIgent;
private Random myRandomGen = new Random(System.Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds));

// Get the next Authorization Number to validate.
public async Task <BaseResponse<AuthorizeResponse>> Get()

int myValue2Authorize = myRandomGen.Next(100000000);
int myValue4FileName = myRandomGen.Next(100000000);
BaseResponse<authorizeresponse> baseResponse = new BaseResponse<authorizeresponse>();
AuthorizeResponse authorizeResponse = new AuthorizeResponse();
authorizeResponse.Authorize = myValue2Authorize;
AuthCode = myValue2Authorize;
baseResponse.Data = authorizeResponse;
baseResponse.Code = "200";
baseResponse.Success = true;
baseResponse.Message = "Operation Successfully";
return (baseResponse);

// Send the xAIgent Request to the dbiXServiceAPI
public async Task<BaseResponse<AppDemoReponse>> Post([FromBody] AppDemoRequest request)

string responseText = "";
BaseResponse<appdemoreponse> baseResponse = new BaseResponse<appdemoreponse>();
AppDemoReponse reponseAppDamo = new AppDemoReponse();

myXAIgent = new xAIEngine.DBIXServiceClient();
if (AuthCode == request.AuthCode) // If the user enters the correct Auth Code

xAIEngine.GetExtractionRequest myGetExtractionRequest = new xAIEngine.GetExtractionRequest();
xAIEngine.ExtractionRequest myExtractionRequest = new xAIEngine.ExtractionRequest();
xAIEngine.GetExtractionResponse myExtractionResponse;
myExtractionRequest.ApplicationID = "";
myExtractionRequest.XTractionDocument = request.XTractionDocument;
myExtractionRequest.LanguageID = request.languageId;
myExtractionRequest.NumberOfPhrasesToReturn = request.NumberOfPhrasesToReturn;
myExtractionRequest.SubscriptionID = "Insert your xAIgent Evaluation Token Here";
myGetExtractionRequest.XtractionRequest = myExtractionRequest;
myExtractionResponse = await myXAIgent.GetExtractionAsync(myGetExtractionRequest);
int myResultsCounter = 1;
// If the xAIgent returns a list of keyphrases, print out each one …
if (myExtractionResponse.GetExtractionResult.KeyPhrases.Length > 0)

foreach (var keyPhrase2Display in myExtractionResponse.GetExtractionResult.KeyPhrases)
// keyPhrase2Display.Phrase = keyPhrase2Display.Phrase
keyPhrase2Display.Phrase = keyPhrase2Display.Phrase.ToUpper();
keyPhrase2Display.Highlight = keyPhrase2Display.Highlight;
responseText = responseText + myResultsCounter.ToString() + ". " + keyPhrase2Display.Phrase + Constants.vbCrLf + "Score: " + keyPhrase2Display.Score.ToString() + Constants.vbCrLf + "Highlight: " + keyPhrase2Display.Highlight + Constants.vbCrLf + Constants.vbCrLf;
myResultsCounter = myResultsCounter + 1;
responseText = "No Results were-returned";
else // The user entered the wrong Auth Code
baseResponse.Success = true;
baseResponse.Message = "un authorization";
baseResponse.Data = reponseAppDamo;
baseResponse.Code = "400";
reponseAppDamo.ResponseText = null;
return baseResponse;
baseResponse.Success = true;
baseResponse.Message = "Operation Complete";
baseResponse.Data = reponseAppDamo;
baseResponse.Code = "200";
reponseAppDamo.ResponseText = responseText;
} catch (Exception ex)
{ responseText = ex.Message.ToString();
baseResponse.Success = false;
baseResponse.Message = responseText;

return baseResponse;

// Get the selected Language …
public async Task <BaseResponse<List<LanguageResponse>>> GetLanguages()
BaseResponse <List<LanguageResponse>> baseResponse = new BaseResponse <List<LanguageResponse>>();
List <LanguageResponse> Lst = new List <LanguageResponse>();
Lst.Add(new LanguageResponse { Id = 0, Name = "AUTO DETECT" });
Lst.Add(new LanguageResponse { Id = 1, Name = "ENGLISH" });
Lst.Add(new LanguageResponse { Id = 2, Name = "FRENCH" });
Lst.Add(new LanguageResponse { Id = 3, Name = "JAPANESE" });
Lst.Add(new LanguageResponse { Id = 4, Name = "GERMAN" });
Lst.Add(new LanguageResponse { Id = 5, Name = "SPANISH" });
Lst.Add(new LanguageResponse { Id = 6, Name = "KOREAN" });
baseResponse.Data = Lst;
baseResponse.Success = true;
baseResponse.Code = "200";
baseResponse.Message = "Operation Complete";
return baseResponse;




NOTE: To test run the React js xAigent demo application please visit (

C Sharp Project VB.NET Project React js Project