Back to Main Menu

Using .Net to access Assetic REST API

Introduction

.Net may be used as the development environment for integrating with Assetic.

 

Some code samples are provided to assist with getting started.

TLS 1.2

Assetic enforces the TLS 1.2 protocol, which is not the default protocol for versions of .Net prior to 4.6.

  • For .NET 4.5. execute the following code before making a connection to Assetic:
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
  • For .NET 4.0. TLS 1.2 is not supported, however if .NET 4.5 (or above) is installed on the target system execute the following code before making a connection to Assetic:
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
  • For .NET 3.5 or below the TLS 1.2 protocol is not supported

Code Sample

The following code sample illustrates the basis steps in creating Work Requests from Assetic

appURI = appSettings["AsseticURI"];  // the ASSETIC Uri appUserName = appSettings["AsseticUserName"]; // the ASSETIC user name running the service appUserToken = appSettings["AsseticUserToken"]; // the ASSETIC token for the user  using (HttpClient client = new HttpClient()) { 	client.BaseAddress = new Uri(appURI); 	client.DefaultRequestHeaders.Accept.Clear();  	// add authorisation objects to header 	client.DefaultRequestHeaders.Authorization = 		new AuthenticationHeaderValue( 			"Basic", 			 Convert.ToBase64String( 			 Encoding.ASCII.GetBytes(string.Format("{0}:{1}", appUserName, appUserToken))));  	string path = appURI + postRequest; // postRequest is api/v2/WorkRequest/  	//newRequest is the Json string in ASSETIC format 	HttpResponseMessage response = client.PostAsync(path,  		new StringContent(newRequest, Encoding.UTF8, "application/json")).Result;  	if (response.IsSuccessStatusCode) 	{ 		// get the id of the request 		var result = response.Headers.Location; 	} }