Site Tools


guides:ws_payloads_send_payload

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
guides:ws_payloads_send_payload [2020/08/23 18:28] – created brett.zamoraguides:ws_payloads_send_payload [2024/03/18 17:51] (current) greg.dapkus
Line 9: Line 9:
 ---- ----
  
-**Purpose:** <color #22b14c>**Retrieve A Payload From A Repository.**</color>+**Purpose:** <color #22b14c>**Send A Payload To A Repository.**</color>
  
  
Line 16: Line 16:
 {{tablelayout?colwidth="75px,575px"&rowsFixed=1&rowsVisible=10&float=center}} {{tablelayout?colwidth="75px,575px"&rowsFixed=1&rowsVisible=10&float=center}}
 ^ Method ^ URL ^ ^ Method ^ URL ^
-GET | <nowiki>https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/{repository}/{payload_name}</nowiki> |+POST | <nowiki>https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/{repository}/{payload_name}</nowiki> |
  
  
Line 83: Line 83:
  
 ---- ----
 +
 +
 +**Comment 1:**
 +
 +Following is a C# / .NET sample code snippet that shows how to call the web services associated with sending a local payload to a remote folder.
 +
 +This snippet was derived from the [[guides:web_service_toolbox_project|Web Service Toolbox]] that is available on the CeRTNA Wiki. The sample application is intended for easy to read demonstration purposes and not production quality code. The [[guides:web_service_toolbox_project|Web Service Toolbox]] application is documented, on the CeRTNA Wiki, to aid in understanding the code snippet shown below.
 +
 +
 +<code C#>
 +private bool SendFile(string strRepositoryType, string strFileName)
 +{
 +    tbMessageLine.Text = "";
 +
 +    bool rc = false;
 +
 +    RestClient client = null;
 +    RestRequest request = null;
 +    IRestResponse response = null;
 +
 +    string strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/user/login";
 +
 +    // Password has to be hashed.
 +    // New convention uses a Salt value from the user record
 +    // See the Login documentation for more detail
 +
 +    string strSalt = GetSalt(tbUserName.Text);
 +    string strPassword = tbPassword.Password.ToString();
 +
 +    string strHashedPassword = HashPassword(strPassword, strSalt);
 +
 +    string strParms = "{\n\t\"user_name\" : \"";
 +    strParms += tbUserName.Text;
 +    strParms += "\",\n\t\"password\" : \"";
 +    strParms += strHashedPassword;
 +    strParms += "\"\n}";
 +
 +    client = new RestClient(strURL);
 +    request = new RestRequest(Method.POST);
 +
 +    request.AddHeader("Cache-Control", "no-cache");
 +    request.AddHeader("Content-Type", "application/json");
 +
 +    request.AddParameter("Login", strParms, ParameterType.RequestBody);
 +    response = client.Execute(request);
 +
 +    if (response.IsSuccessful)
 +    {
 +        tbMessageLine.Text = "Sending XML file "+strFileName;
 +                
 +        var jsonResult1 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +        string token = jsonResult1.access_token;
 +
 +        FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read);
 +
 +        XmlDocument xmlDoc = new XmlDocument();
 +
 +        xmlDoc.Load(fs);
 +
 +        strURL = null;
 +        client = null;
 +        request = null;
 +        response = null;
 +
 +        strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/" + strRepositoryType;  
 +
 +        client = new RestClient(strURL);
 +        request = new RestRequest(Method.POST);
 +
 +        request.AddHeader("Cache-Control", "no-cache");
 +        request.AddHeader("access_token", token);
 +        request.AddHeader("content-type", "text/plain");
 +        request.AddParameter("undefined", xmlDoc.InnerXml, ParameterType.RequestBody);
 +        response = client.Execute(request);
 +
 +        if (response.IsSuccessful)
 +        {
 +            var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +            string strRemoteFileName = jsonResult2.result;
 +
 +            // You must finalize the remote file to change the extension from .tmp to .xml
 +            
 +            string strAction = "finalize";
 +
 +            strURL = null;
 +            client = null;
 +            request = null;
 +            response = null;
 +
 +            strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/" + strRepositoryType + "/" + strRemoteFileName + "?operation=" + strAction;  
 +
 +            client = new RestClient(strURL);
 +            request = new RestRequest(Method.PATCH);
 +
 +            request.AddHeader("Cache-Control", "no-cache");
 +            request.AddHeader("access_token", token);
 +            response = client.Execute(request);
 +
 +            if (response.IsSuccessful)
 +            {
 +                tbMessageLine.Text = "XML file " + strFileName+" successfully sent.";
 +                rc = true;
 +            }
 +            else
 +            {
 +                var jsonResult3 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +                string strMessage = jsonResult3.Exception.Message;
 +                tbMessageLine.Text = strMessage;
 +            }
 +        }
 +        else
 +        {
 +            var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +            string strMessage = jsonResult2.Exception.Message;
 +            tbMessageLine.Text = strMessage;
 +        }
 +    }
 +    else
 +    {
 +        var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +        tbMessageLine.Text = jsonResult2.ToString();
 +    }
 +
 +    return (rc);
 +}
 +</code>
 +
 +
 +**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://www.getpostman.com/apps
  
guides/ws_payloads_send_payload.1598207298.txt.gz · Last modified: by brett.zamora