Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Image RemovedAdonis
HOW TO: Consume ADONIS WEB SERVICES

Anchor
_GoBack
_GoBack

...

Using the api setting up the authentication


Step 1: Under administrator login open Configurations -> General -> Personal Portal Service. Define password for "Adonis_API" user.


Step 2: Use method GNL_API_AUTHENTICATION with login "Adonis_API" and password defined on step 1. To generate security token.
Step 3: Under administrator login open Configurations -> General -> Personal Portal Service. Click "OPEN CREW PORTAL SERVICE API DOCUMENTATION" to explore available API methods via swagger.


Example: Client for CrewPortalWebServices on C#

Step 1: Add reference to the Adonis Web Service in Visual Studio.

Step 2: Add endpoint in client web.config file. Section System.ServiceModel.

Code Block
languagexml
<client>
<endpoint behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="ConsumeFromController" contract="CPWebServiceReference.ICrewPortalWebService" name="ConsumeFromController" />
<endpoint behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="ConsumeFromControllerSecure" contract=" CPWebServiceReference.ICrewPortalWebService" name="ConsumeFromControllerSecure" />
</client> 


<client>
<endpoint behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="ConsumeFromController" contract="CPWebServiceReference.ICrewPortalWebService" name="ConsumeFromController" />
<endpoint behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="ConsumeFromControllerSecure" contract=" CPWebServiceReference.ICrewPortalWebService" name="ConsumeFromControllerSecure" />
</client>


Step 3: Call the service methods.

Code Block
languagec#
public class CPServiceWrapper
{
public CPServiceWrapper(){} 
private bool isSecureConnection(string serviceURL)
{
return (serviceURL.Substring(0, 5)) == "https";
} 
private ChannelFactory<ICrewPortalWebService> createChannelFactory(string serviceURL)
{
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
var factory = new ChannelFactory<ICrewPortalWebService>(isSecureConnection(serviceURL) ? "ConsumeFromControllerSecure": "ConsumeFromController"); 
foreach (var behavior in factory.Endpoint.EndpointBehaviors)
{
WebHttpBehavior web = behavior as WebHttpBehavior;
if (web != null)
web.DefaultOutgoingRequestFormat = System.ServiceModel.Web.WebMessageFormat.Json;
} 
factory.Endpoint.Address = new EndpointAddress(serviceURL);
return factory;
} 
public string GNL_API_AUTHENTICATION(string login, string password, int lifeTime, string serviceURL)
{
try
{
using (var factory = createChannelFactory(serviceURL))
{
var channel = factory.CreateChannel();
var requesAPIAuthentication = new RequestAPIAuthentication ();
requesAPIAuthentication.Login = login;
requesAPIAuthentication.Password = password;
requesAPIAuthentication.LifeTime = lifeTime; 
var response = channel. AUTHENTICATION (requesAPIAuthentication);
if (response != null && response.Authentication_Approved)
{
return response.Authentication_Token;
} 
if (response != null && !response.Authentication_Approved)
{
return response.Authentication_ReasonDenied;
} 
return String.Empty;
}
}
catch (Exception e)
{
return e.Message;
} 
}
}


You could do this in different ways. In this example we consume service via ChannelFactory. For better flexibility you could use our class CPServiceWrapper.cs
public class CPServiceWrapper
{
public CPServiceWrapper(){}
private bool isSecureConnection(string serviceURL)
{
return (serviceURL.Substring(0, 5)) == "https";
}
private ChannelFactory<ICrewPortalWebService> createChannelFactory(string serviceURL)
{
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
var factory = new ChannelFactory<ICrewPortalWebService>(isSecureConnection(serviceURL) ? "ConsumeFromControllerSecure": "ConsumeFromController");
foreach (var behavior in factory.Endpoint.EndpointBehaviors)
{
WebHttpBehavior web = behavior as WebHttpBehavior;
if (web != null)
web.DefaultOutgoingRequestFormat = System.ServiceModel.Web.WebMessageFormat.Json;
}
factory.Endpoint.Address = new EndpointAddress(serviceURL);
return factory;
}
public string GNL_API_AUTHENTICATION(string login, string password, int lifeTime, string serviceURL)
{
try
{
using (var factory = createChannelFactory(serviceURL))
{
var channel = factory.CreateChannel();
var requesAPIAuthentication = new RequestAPIAuthentication ();
requesAPIAuthentication.Login = login;
requesAPIAuthentication.Password = password;
requesAPIAuthentication.LifeTime = lifeTime;
var response = channel. AUTHENTICATION (requesAPIAuthentication);
if (response != null && response.Authentication_Approved)
{
return response.Authentication_Token;
}
if (response != null && !response.Authentication_Approved)
{
return response.Authentication_ReasonDenied;
}
return String.Empty;
}
}
catch (Exception e)
{
return e.Message;
}
}
}
And generate token using CPServiceWrapper class:
String token = new CPServiceWrapper().GNL_API_AUTHENTICATION("Adonis_API", password, TokenLifeTime, serviceURL);

Example: Call AdonisWebServices using jQuery.


When generate security token browser side you MUST use https connection for security reasons. Rest of methods you could call via http.
Example of generate security token:
var requestAPIAuthentication = new Object();
requestAPIAuthentication.Login = "Adonis_API";
requestAPIAuthentication.Password = "password";
requestAPIAuthentication.LifeTime = 1200;
$.ajax({
url: $('#CPServiceURL').val() + "/GNL_API_AUTHENTICATION ",
data: '{"credentials":' + JSON.stringify(requestAPIAuthentication) + '}',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
cache: false,
async: true,
success: function (data) {
...
},
error: function (xhr, textStatus, error)
{
console.log("Error: " + error.toString());
}
});

Example consume DB views via API (AdonisIntegrationWebService)

...