Web Service: LockRemoteXmlFile
The LockRemoteXmlFile web service is used to place a lock on an XML file that resides in a remote shared folder. This call will typically precede a call to the GetRemoteXmlFile web service.
The LockRemoteXmlFile web service, returns a lock key. The lock key is a required parameter for both the GetRemoteXmlFile and the RemoveLockedRemoteXmlFile web service calls.
Request Endpoint
Method | URL |
---|---|
POST | https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/lockremotexmlfile |
Request Body
This endpoint accepts request body parameters using an application/json format.
Request Headers
Key | Value |
---|---|
Content-Type | application/json |
JSON Request Parameters
Parm Name | Req/Opt | Format | Description |
---|---|---|---|
checksum | Required | [string] | Locally calculated binary checksum value converted to a Base64 string. |
JSON Response Parameters
Parm Name | Format | Description |
---|---|---|
checksum_key | [string] | The key of the checksum record that was stored in the CeRTNA Portal. |
code | [string] | Exception conditions will result in code/message being returned. |
message | [string] | Longer description of exception condition. |
As noted, any condition that results in an unsuccessful call to the StoreChecksum web service will produce a JSON formatted response with a code and message property populated. Successful calls will result in the checksum_key property being returned. The checksum_key is a required parameter of the ValidateChecksum web service.
Sample Request
Endpoint:
https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/storechecksum
Headers:
Content-Type: application/json
Body:
{ "checksum" : "1/l1YnJ1dnWFVbjEcUfp3IkBkPb1XBWhdC34T6nJ3YB859YuAtbhUUEG8Gcwimd1" }
Sample Response
Status Code: 200
{ "checksum_key": "315E7449-1A67-44A8-BCF4-7EB43666D54D" }
OR
Status Code: 500 (When an error occurs.)
(example 1)
{ "Exception": { "Code": "DatabaseError", "Message": "Procedure or function 'spStoreChecksumValue' expects parameter '@CHECKSUM_VALUE', which was not supplied." } }
Additional Comments
Comments and sample code are provided for reference purposes only and are not intended to show all exception handling conditions and/or completed code blocks.
Comment 1:
The StoreChecksum web service requires a Base64 encoded SHA384 checksum to be provided as one of the parameters. Following is a C# / .NET sample code snippet that shows how to generate a SHA3 checksum and convert the hash to a Base64 string:
// The following strBase64DocValue value is retrieved from the DOCUMENT child node of the EMBEDDED_FILE node in the XML document. string strBase64DocValue = " SUkqALLnAAAtVZDKI+R4jhk…"; // Get your Base64 string from the XML doc. string strBase64HashValue = getBase64Hash(strBase64DocValue); // Use this value in your web service call public static string getBase64Hash(string strB64Source) { Encoding u8 = Encoding.UTF8; // We use UTF8 encoding byte[] b64Bytes = u8.GetBytes(strB64Source); // Put the Document B64 string into a byte array byte[] b64HashBytes = SHA384.Create().ComputeHash(b64Bytes); // Compute the SHA384 hash //Convert the SHA384 hash to a Base64 string string strB64Value = System.Convert.ToBase64String(b64HashBytes, 0, b64HashBytes.Length); return strB64Value; }
Comment 2:
Following is a C# / .NET sample code snippet that shows how to call the StoreChecksum web service. Your code will supply the values for the various parameters based on the following:
Parameter | Source |
---|---|
checksum | The Base64 encoded value of the SHA384 binary checksum that was calculated for the DOCUMENT string. |
Public static void StoreChecksumExample() { // In this example I am picking up the checksum value I calculated from a // form field in the sample application that is available on this Wiki. string strChecksumValue = tbChecksumValue.Text; // The following value was obtained from your call to the Login web service. string token = "ab34xyz3..."; strURL = null; client = null; request = null; response = null; strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/storechecksum"; client = new RestClient(strURL); request = new RestRequest(Method.POST); strParms = "{\n\t\"checksum\" : \""; strParms += strChecksumValue; strParms += "\"\n}"; request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Content-Type", "application/json"); request.AddHeader("access_token", token); request.AddParameter("StoreChecksum", strParms, ParameterType.RequestBody); response = client.Execute(request); if (response.IsSuccessful) { var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content); string strChecksumKey = jsonResult2.checksum_key; // (Agents) Update the RequestChecksumValue property of the PRIA_DOCUMENT node with the value of strChecksumKey // or // (Counties) Update the ResponseChecksumValue property of the PRIA_DOCUMENT node with the value of strChecksumKey } else { var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content); string str_ErrorCode = jsonResult2.ToString(); // Do something with the error result } }
Comment 3:
Please note that before calling the CeRTNA web services you must establish the SecurityProtocol in your ServicePointManager. An example is shown below. The currently recommended protocol is Tls12.
public MainWindow() { InitializeComponent(); System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; }
Comment 4:
CeRTNA has posted a simple Visual Studio 2015 WPF/C# project on the CeRTNA Wiki that demonstrates how to look up values in an XML file and how to use the Login, StoreChecksum, and ValidateChecksum web services. The project can be downloaded from the Wiki. As stated earlier, the purpose of the code samples is not to demonstrate well structured code, but rather to provide a very simple, functional sample, that you can use for reference in adding CeRTNA web service calls to your existing application. The code sample is provided as is, however, your production code would be expected to contain more extensive error handling, etc.
Comment 5:
A nice utility for experimenting with web service calls is POSTMAN. You can download a free version of POSTMAN from the following URL: https://www.getpostman.com/apps