Categories
.NET Web Services

Using the JMT Web Service from .NET

Overview

As part of the strategy for increasing the capabilities for Master Terminal to be integrated into an organisation’s information infrastructure, more and more functionality is constantly being exposed via the Master Terminal Web Service in each new release.
Once functionality has been exposed via the Master Terminal Web Service as part of a release, any authenticated application can use the web services that they have been granted access to, using whatever web service consumer technology they have available.
To help with the development of these client applications, we have created this blog entry to demonstrate the process of creating a very simple client application to access the Master Terminal Web Service using Visual Studio 2013 and C# .NET.  The key elements to the process are the initial Service Reference creation from the published WSDL, and then the management of the important session information that the Web Service requires to ensure that requests are only coming from authenticated users.

Getting Started

For the purposes of the example, we will just create a very basic Console application, using only the synchronous versions of the Web Service calls.  Obviously any robust client application being developed would most likely make use of asynchronous calls to the Web Service, as is the norm.

Finding the WSDL URL

Before you start, you will need to know how to find the WSDL for the Master Terminal Web Service you wish to connect to.  As a convention for Master Terminal installations, the endpoint URL for the Web Service will be something like:
http://www.myjmtport.com/bin_public/jadehttp.dll?JMTWebService
If you navigate to your particular Web Service correctly you will get a page something like the following:
Clicking through the JMTSecureService link on the page will display a page listing the available services for that part of the Web Service, and a link to the WSDL you will need:
Clicking the here link will display the WSDL, and the address bar will have the entire URL you will require in Visual Studio:

Copy the entire WSDL URL into the clipboard for later use.

Importing the WSDL

In your Visual Studio project, you will need to import the WSDL as a Service Reference.  Right-click on References in the Solution Explorer, and select Add Service Reference.

Paste the full WSDL URL gathered above into the Address: field, and click Go.  Enter a value in the Namespace: field, and click OK.
The JMTWebService will have been created as a Service Reference in your solution.  Double-clicking the JMTWebService will open the Object Browser and allow viewing of all the imported components.
Also, as a part of the Service Reference import, details of the various Web Service endpoints will be added to the App.config for your solution.
Once your application is up and running, the App.config can be changed to direct requests to Production or Test environments as required.

Creating a Client Application

Establishing a Session

The first step in a client application is to create an authenticated session in Master Terminal, and this is done via the JMTSecureService logon method.
Example code is as follows:
// Create a SOAP client for the JMTSecureService
var secureService = new JMTWebService.JMTSecureServiceSoapClient();

// Just confirming creation is correct
Console.WriteLine(secureService.Endpoint.Address);

// Need an empty header variable to receive header details from logon
JMTWebService.JadeSessionHeader header = null;

// Create logon parameter object
var logon = new JMTWebService.logon();

// Replace these with a valid JMT usercode and password
logon.userId = "JMTUSER";
logon.password = "password1";

// Call the logon service
var logonResponse = secureService.logon(ref header, logon);

The logonResponse.logonResult property must be checked – a null result signifies a valid logon, anything else will be the error message encountered.

The passed in header will be populated by the call, and the sessionId value needs to be saved off to associate any subsequent calls to the Web Service to this validated session.

Example code for checking the result is:

// Check the response (null is successful)
if (logonResponse.logonResult == "")
{
   Console.WriteLine("Logon successful, sessionId={0}", header.sessionId);
else
{
 Console.WriteLine("Logon unsuccessful, result={0}", logonResponse.logonResult);
}

Using the Validated Session

Once a valid session has been established, this must be used for subsequent calls, as in the following example:

// Now use the valid sessionId to make a validated request
var uiService = new JMTWebService.JMTUserInterfaceServiceSoapClient();

// In a multi-terminal operation, need to check which terminal our session is connected to
var getCurrentTerminal = new JMTWebService.getCurrentTerminal();

var terminalResponse = uiService.getCurrentTerminal(ref header, getCurrentTerminal);

Console.WriteLine("Current Terminal is {0} : {1}",
    terminalResponse.getCurrentTerminalResult.terminal.code,
    terminalResponse.getCurrentTerminalResult.terminal.name);

Sample C# Console Application

The following link contains the sample application referred to in this blog:

2 replies on “Using the JMT Web Service from .NET”

Hey I am a user of master terminal and in my organization we are working towards automation of some flow for that we are integrating with Master Terminal via Soap API using wsdl provided, how ever due to lack of documentation I am not able to integrate it via code(Java). Any help in this regard will be appreciated.

Hello, Documentation for the SOAP web sites is available. The documentation is shipped with every release in the form of an HTML file. The documentation will be on the server that MTN is installed on. If you need any further help then you should contact your customer support manager.

Leave a Reply

Your email address will not be published. Required fields are marked *