REST Interface XML, request / response, possibilities

Noah Aas 260 Reputation points
2024-05-16T16:25:49.54+00:00

I have received from the customer. Three requests ToDo:

Server: sapbcprod1.xc-automation.co.at Port: 8087

Folder: /invoke/COATING/

User (Base64): COAT

Password (Base64): to be defined Encoding: UTF-8

A) Replace data

<biztalk_1 xmlns="urn:biztalk-org:biztalk:biztalk_1">
	<body>
		<doc:Z_COATING_MAT_STAT xmlns:doc="urn:sap-com:document:sap:rfc:functions" xmlns="">
			#_DATA_#
		</doc:Z_COATING_MAT_STAT >
	</body>
</biztalk_1>

B) Replace data

<root xmlns="urn:biztalk-org:biztalk:root">
	<body>
		<doc:Z_COATING_ORDER xmlns:doc="urn:sap-com:document:sap:rfc:functions" xmlns="">
			<IM_RUECK>#_DATA_#</IM_RUECK>
		</doc:Z_COATING_ORDER >
	</body>
</root>

C) Create automatically

<root xmlns="urn:biztalk-org:biztalk:root">
	<body>
		<doc:Z_COATING_PANEL xmlns:doc="urn:sap-com:document:sap:rfc:functions" xmlns="">
			<IM_RUECK>
			 <NEST>1
		       <STATE>1</SERNR>
			   <SERNR>0815-001</SERNR>
			 </NEST>
			 <NEST>2
		       <STATE>0</SERNR>
			   <SERNR>0815-002</SERNR>
			 </NEST>
			 <NEST>3
		       <STATE>1</SERNR>
			   <SERNR>0815-003</SERNR>
			 </NEST>
			</IM_RUECK>
		</doc:Z_COATING_PANEL >
	</body>
</root>

Now I should send this request to a REST server as a request using Replace #DATA#

How can I do this, solve this? HttpClient? How I can serialize and deserialize with XML? The most samples are JSON

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,418 questions
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 38,021 Reputation points Microsoft Vendor
    2024-05-17T09:04:17.1233333+00:00

    Hi @Noah Aas , Welcome to Microsoft Q&A,

    You can use the HttpClient class from the System.Net.Http namespace. Here's a step-by-step guide to achieve this:

    Create the XML content: You'll need to create an XML string that you want to send in the POST request.

    Set up the HttpClient: Initialize an instance of the HttpClient.

    Create the HttpContent: Wrap the XML string in a StringContent object and set the appropriate media type.

    Send the POST request: Use the PostAsync method of HttpClient to send the request.

    Handle the response: Process the response from the server.

    Here's a complete example:

    using System;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    
    class Program
    {
        static async Task Main(string[] args)
        {
            // Your XML string
            string xmlData = @"<Request><Data>Hello, World!</Data></Request>";
    
            // The URL to send the POST request to
            string url = "https://example.com/api/endpoint";
    
            // Create a new HttpClient instance
            using (HttpClient client = new HttpClient())
            {
                // Set the content type to XML
                HttpContent content = new StringContent(xmlData, Encoding.UTF8, "application/xml");
    
                // Send the POST request
                HttpResponseMessage response = await client.PostAsync(url, content);
    
                // Ensure the response was successful, or throw an exception
                response.EnsureSuccessStatusCode();
    
                // Read the response content
                string responseContent = await response.Content.ReadAsStringAsync();
    
                // Print the response
                Console.WriteLine(responseContent);
            }
        }
    }
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful