REST interface possibilities

Noah Aas 440 Reputation points
2024-07-04T17:26:43.7733333+00:00

Hello, I have seen a code snippet like this, can I return more than two objects in this task? Then I can ask it like this.

bool responseState = false;
string responseData = "";

 (responseState, responseData) = await ScadaClient.PostXmlToScadaAsync(CFG.SAP_Server, sXmlOrderData);
 
  Log.Info("RequestRecipeFromScadaAsync() Scada-Call response state '" + (responseState ? "successful" : "failed") + "'.");
}

if (!responseState)
{

}


///////
class ScadaClient
{
	private static readonly HttpClient client = new HttpClient();

	public static async Task<(bool success, string responseData)> PostXmlToScadaAsync(string url, string xmlData)
	{
		try
		{
			if (string.IsNullOrEmpty(url))
			{
				return (false, "PostXmlToScadaAsync() Input-URL no data.");
			}

			var content = new StringContent(xmlData, Encoding.UTF8, "text/xml");

			HttpResponseMessage response = await client.PostAsync(url, content);

			if (response == null)
			{
				return (false, "No answer Scada module.");
			}

The questions. Don't I have to create a new Task instance here? Return values can be 0 2 or n variables, right? Do I see that correctly?

Could use a text file as a template, then fill variables or assign values ​​using the **replace **method. How should I solve this with the authorization?

Like this

<q1:COM_1 xmlns:q1="urn:biztalk-org:biztalk:biztalk_1">
  <q1:body>
    <Z_COATING_ORDER xmlns="urn:sap-com:document:sap:rfc:functions">
      <IM_BACK>$$$MyValue$$$</IM_BACK>
    </Z_COATING_ORDER>
  </q1:body>
</q1:COM_1>

<IM_BACK>$$$MyValue$$$</IM_BACK> Replace $$$MyValue$$$

No problems with namespace. Is it a good way?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,913 questions
{count} votes

Accepted answer
  1. Ganeshkumar R 660 Reputation points
    2024-07-04T17:43:51.35+00:00

    Hello @Noah Aas ,
    Yes. This approach provides flexibility and allows you to efficiently manage dynamic content and secure communications in your application.

    If you want to use a text file as a template and replace variables, you can use the Replace method. This can be useful for dynamically generating XML content.

    When dealing with authorization, you often need to include an authorization header in your HTTP requests. Here’s how you can add an authorization header to your HttpClient requests.

    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your-access-token");


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.