guides:ws_payloads_retrieve_payload
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| guides:ws_payloads_retrieve_payload [2020/08/23 17:57] – brett.zamora | guides:ws_payloads_retrieve_payload [2020/08/24 21:24] (current) – brett.zamora | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ==== payloads: | ==== payloads: | ||
| - | The payloads web service is a REST structured service that derives its functionality based on syntax used when calling the web service. To retrieve a payload from a repository, call the payloads web service with a repository name and the payload file name. | + | The payloads web service is a REST structured service that derives its functionality based on syntax used when calling the web service. To retrieve a payload from a repository, call the payloads web service with a repository name and the payload file name. |
| + | |||
| + | The payload will be returned in the body of the response as a UTF-8 encoded XML string. | ||
| + | |||
| + | **Important: | ||
| ---- | ---- | ||
| Line 16: | Line 21: | ||
| **Variables: | **Variables: | ||
| - | {{tablelayout? | + | {{tablelayout? |
| ^ Variable ^ Usage ^ Description ^ | ^ Variable ^ Usage ^ Description ^ | ||
| | {repository} | Required | The name of the repository | | | {repository} | Required | The name of the repository | | ||
| Line 51: | Line 56: | ||
| - | <color # | + | <color # |
| Status Code: 200 | Status Code: 200 | ||
| + | |||
| + | <code xml> | ||
| + | <?xml version=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <KEY _Name=" | ||
| + | < | ||
| + | < | ||
| + | <PACKAGE CountyFIPSCode=" | ||
| + | < | ||
| + | <GRANTOR _FirstName=" | ||
| + | <GRANTEE _FirstName=" | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | <STATUS _Code=" | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | |||
| + | **OR** | ||
| + | |||
| + | Status Code: 500 (When an error occurs.) | ||
| <code json> | <code json> | ||
| - | [ | + | { |
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | |||
| + | **Comment 1:** | ||
| + | |||
| + | Following is a C# / .NET sample code snippet that shows how to call the web services associated with retrieve a payload from a remote folder/ | ||
| + | |||
| + | This snippet was derived from the [[guides: | ||
| + | |||
| + | The general process flow for retrieving a payload from a remote folder is: | ||
| + | |||
| + | * Lock the remote payload. | ||
| + | * Retrieve the remote payload. | ||
| + | * Validate your retrieved payload. | ||
| + | * If the validation is successful: Delete the locked remote payload. | ||
| + | * Otherwise: Unlock the remote payload. (Troubleshoot or re-retrieve.) | ||
| + | |||
| + | |||
| + | The following snippets show the process, minus the validation, step... | ||
| + | |||
| + | |||
| + | ** Snippet 1: ** | ||
| + | |||
| + | <code C#> | ||
| + | private void btnRetrieve_Click(object sender, RoutedEventArgs e) | ||
| + | { | ||
| + | bool rc; | ||
| + | |||
| + | string strLocalFolder = tbLocalFolderName.Text; | ||
| + | string strRepository = (cbRepository.SelectedItem as ComboBoxItem).Content as string; | ||
| + | |||
| + | // See payloads: | ||
| + | |||
| + | string[] strFolderFileNames = getRepositoryFileNames(strRepository); | ||
| + | |||
| + | if (strFolderFileNames != null) | ||
| { | { | ||
| - | | + | |
| - | "RepositoryName": | + | |
| - | }, | + | // Lock the payload |
| + | rc = LockUnlockRemoteFile(strRepository, | ||
| + | // Retrieve the payload | ||
| + | DownloadRemoteFile(strRepository, | ||
| + | // Delete the remote payload | ||
| + | rc = DeleteRemoteFile(strRepository, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ** Snippet 2: Lock The Payload ** | ||
| + | |||
| + | <code C#> | ||
| + | private bool LockUnlockRemoteFile(string strRepositoryType, string strFileName, | ||
| + | { | ||
| + | bool rc = false; | ||
| + | |||
| + | if (strAction == " | ||
| { | { | ||
| - | "Count": 0, | + | |
| - | "RepositoryName": " | + | } |
| - | }, | + | else if (strAction == "unlock") |
| { | { | ||
| - | "Count": 96, | + | |
| - | " | + | } |
| - | | + | |
| { | { | ||
| - | "Count": | + | |
| - | " | + | |
| } | } | ||
| - | ] | + | |
| + | RestClient client = null; | ||
| + | RestRequest request = null; | ||
| + | IRestResponse response = null; | ||
| + | |||
| + | string strURL = " | ||
| + | |||
| + | // Password has to be hashed. | ||
| + | // New convention uses a Salt value from the user record | ||
| + | // See the Login web service for more detail. | ||
| + | |||
| + | string strSalt = GetSalt(tbUserName.Text); | ||
| + | string strPassword = tbPassword.Password.ToString(); | ||
| + | |||
| + | string strHashedPassword = HashPassword(strPassword, | ||
| + | |||
| + | string strParms = " | ||
| + | strParms += tbUserName.Text; | ||
| + | strParms += " | ||
| + | strParms += strHashedPassword; | ||
| + | strParms += " | ||
| + | |||
| + | client = new RestClient(strURL); | ||
| + | request = new RestRequest(Method.POST); | ||
| + | |||
| + | request.AddHeader(" | ||
| + | request.AddHeader(" | ||
| + | |||
| + | request.AddParameter(" | ||
| + | response = client.Execute(request); | ||
| + | |||
| + | if (response.IsSuccessful) | ||
| + | { | ||
| + | var jsonResult1 = JsonConvert.DeserializeObject< | ||
| + | string token = jsonResult1.access_token; | ||
| + | |||
| + | strURL = null; | ||
| + | client = null; | ||
| + | request = null; | ||
| + | response = null; | ||
| + | |||
| + | strURL = " | ||
| + | |||
| + | client = new RestClient(strURL); | ||
| + | request = new RestRequest(Method.PATCH); | ||
| + | |||
| + | request.AddHeader(" | ||
| + | request.AddHeader(" | ||
| + | response = client.Execute(request); | ||
| + | |||
| + | if (response.IsSuccessful) | ||
| + | { | ||
| + | if (strAction == " | ||
| + | { | ||
| + | tbMessageLine.Text = " | ||
| + | } | ||
| + | else if (strAction == " | ||
| + | { | ||
| + | tbMessageLine.Text = " | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | tbMessageLine.Text = ""; | ||
| + | } | ||
| + | rc = true; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | var jsonResult2 = JsonConvert.DeserializeObject< | ||
| + | string strMessage = jsonResult2.Exception.Message; | ||
| + | tbMessageLine.Clear(); | ||
| + | tbMessageLine.Text = strMessage; | ||
| + | } | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | var jsonResult2 = JsonConvert.DeserializeObject< | ||
| + | tbMessageLine.Text = jsonResult2.ToString(); | ||
| + | } | ||
| + | return (rc); | ||
| + | } | ||
| </ | </ | ||
| + | ** Snippet 3: Retrieve The Payload ** | ||
| - | **OR** | + | <code C#> |
| + | private void DownloadRemoteFile(string strRepositoryType, | ||
| + | { | ||
| + | tbMessageLine.Text = ""; | ||
| - | Status Code: 500 (When an error occurs.) | + | RestClient client = null; |
| + | RestRequest request = null; | ||
| + | IRestResponse response = null; | ||
| - | < | + | string strURL = " |
| + | |||
| + | // Password has to be hashed. | ||
| + | // New convention uses a Salt value from the user record | ||
| + | // See the Login web service for more detail | ||
| + | |||
| + | string strSalt = GetSalt(tbUserName.Text); | ||
| + | string strPassword = tbPassword.Password.ToString(); | ||
| + | |||
| + | string strHashedPassword = HashPassword(strPassword, | ||
| + | |||
| + | string strParms = " | ||
| + | strParms += tbUserName.Text; | ||
| + | strParms += " | ||
| + | strParms += strHashedPassword; | ||
| + | strParms += " | ||
| + | |||
| + | client = new RestClient(strURL); | ||
| + | request = new RestRequest(Method.POST); | ||
| + | |||
| + | request.AddHeader(" | ||
| + | request.AddHeader(" | ||
| + | |||
| + | request.AddParameter(" | ||
| + | response = client.Execute(request); | ||
| + | |||
| + | if (response.IsSuccessful) | ||
| + | { | ||
| + | var jsonResult1 = JsonConvert.DeserializeObject<dynamic> | ||
| + | string token = jsonResult1.access_token; | ||
| + | |||
| + | strURL = null; | ||
| + | client = null; | ||
| + | request = null; | ||
| + | response = null; | ||
| + | |||
| + | strURL = " | ||
| + | |||
| + | client = new RestClient(strURL); | ||
| + | request = new RestRequest(Method.GET); | ||
| + | |||
| + | request.AddHeader(" | ||
| + | request.AddHeader(" | ||
| + | request.AddHeader(" | ||
| + | response = client.Execute(request); | ||
| + | |||
| + | if (response.IsSuccessful) | ||
| + | { | ||
| + | // Note: Do not try to use the LoadXml API as it does not account for the encoding preamble. | ||
| + | |||
| + | XmlReader myXmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(response.Content))); | ||
| + | XmlDocument xmlDoc = new XmlDocument(); | ||
| + | xmlDoc.Load(myXmlReader); | ||
| + | xmlDoc.Save(strLocalFolder + " | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | var jsonResult2 = JsonConvert.DeserializeObject< | ||
| + | string strMessage = jsonResult2.Exception.Message; | ||
| + | tbMessageLine.Text = strMessage; | ||
| + | } | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | var jsonResult2 = JsonConvert.DeserializeObject< | ||
| + | tbMessageLine.Text = jsonResult2.ToString(); | ||
| + | } | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | ** Snippet 4: Delete The Remote Payload ** | ||
| + | |||
| + | <code C#> | ||
| + | private bool DeleteRemoteFile(string strRepositoryType, | ||
| { | { | ||
| - | "Exception": { | + | |
| - | "Code": "InvalidUserCredentials", | + | |
| - | "Message": "Invalid Session Id" | + | bool rc = false; |
| + | |||
| + | RestClient client = null; | ||
| + | RestRequest request = null; | ||
| + | IRestResponse response = null; | ||
| + | |||
| + | string strURL = "https:// | ||
| + | |||
| + | // Password has to be hashed. | ||
| + | // New convention uses a Salt value from the user record | ||
| + | // See the Login web service for more detail | ||
| + | |||
| + | string strSalt = GetSalt(tbUserName.Text); | ||
| + | string strPassword = tbPassword.Password.ToString(); | ||
| + | |||
| + | string strHashedPassword = HashPassword(strPassword, | ||
| + | |||
| + | string strParms = "{\n\t\" | ||
| + | | ||
| + | strParms += "\", | ||
| + | strParms += strHashedPassword; | ||
| + | strParms += " | ||
| + | |||
| + | client = new RestClient(strURL); | ||
| + | request = new RestRequest(Method.POST); | ||
| + | |||
| + | request.AddHeader(" | ||
| + | | ||
| + | |||
| + | request.AddParameter(" | ||
| + | response = client.Execute(request); | ||
| + | |||
| + | if (response.IsSuccessful) | ||
| + | { | ||
| + | var jsonResult1 = JsonConvert.DeserializeObject< | ||
| + | string token = jsonResult1.access_token; | ||
| + | |||
| + | strURL = null; | ||
| + | client = null; | ||
| + | request = null; | ||
| + | response = null; | ||
| + | |||
| + | strURL = "https:// | ||
| + | |||
| + | client = new RestClient(strURL); | ||
| + | request = new RestRequest(Method.DELETE); | ||
| + | |||
| + | request.AddHeader(" | ||
| + | request.AddHeader(" | ||
| + | response = client.Execute(request); | ||
| + | |||
| + | if (response.IsSuccessful) | ||
| + | { | ||
| + | tbMessageLine.Text = " | ||
| + | rc = true; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | var jsonResult2 = JsonConvert.DeserializeObject< | ||
| + | string strMessage = jsonResult2.Exception.Message; | ||
| + | tbMessageLine.Text = strMessage; | ||
| + | } | ||
| } | } | ||
| + | else | ||
| + | { | ||
| + | var jsonResult2 = JsonConvert.DeserializeObject< | ||
| + | tbMessageLine.Text = jsonResult2.ToString(); | ||
| + | } | ||
| + | return (rc); | ||
| } | } | ||
| </ | </ | ||
| - | ---- | + | **Comment 2:** |
| + | |||
| + | A nice utility for experimenting with web service calls is POSTMAN. You can download a free version of POSTMAN from the following URL: https:// | ||
| + | |||
guides/ws_payloads_retrieve_payload.1598205436.txt.gz · Last modified: by brett.zamora
