need to integrate SOAP Request in dotnet maui
requst and responce body are in xml formate
need to integrate SOAP Request in dotnet maui
requst and responce body are in xml formate
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
sasikala sRank #1,091 · 1.7K reputationPosted Feb 11, 2025, 12:07 AM EST
Integrating a SOAP request in a .NET MAUI application involves sending an XML-formatted request to a SOAP web service and handling the XML response. Below are the steps to achieve this:
Step 1: Create the SOAP Request XMLYou need to construct your SOAP request as an XML string. Here’s a basic example:
You can use
HttpClientto send the SOAP request. Here’s a sample method that demonstrates how to do this:using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; public class SoapServiceClient { private readonly HttpClient _httpClient; public SoapServiceClient() { _httpClient = new HttpClient(); } public async Task CallSoapServiceAsync(string url, string soapRequestXml) { \/\/ Set up the request var request = new HttpRequestMessage(HttpMethod.Post, url); request.Headers.Add(\"SOAPAction\", \"http:\/\/tempuri.org\/YourMethod\"); \/\/ Replace with your method request.Content = new StringContent(soapRequestXml, Encoding.UTF8, \"text\/xml\"); \/\/ Send the request HttpResponseMessage response = await _httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); \/\/ Read the response string responseContent = await response.Content.ReadAsStringAsync(); return responseContent; \/\/ This is your SOAP response } }You can call the SOAP service method from your MAUI application like this:
private async void OnCallSoapServiceButtonClicked(object sender, EventArgs e) { var soapClient = new SoapServiceClient(); string url = \"http:\/\/your-soap-service-url\"; \/\/ Replace with your SOAP service URL string soapRequestXml = @\"YourValue1YourValue2\"; try { string response = await soapClient.CallSoapServiceAsync(url, soapRequestXml); \/\/ Process the response here Console.WriteLine(response); } catch (Exception ex) { \/\/ Handle exceptions Console.WriteLine($\"Error calling SOAP service: {ex.Message}\"); } }You’ll likely want to parse the XML response. You can use
Example of Parsing the Response:System.Xml.Linqor any XML parsing library of your choice to handle the response data.using System.Xml.Linq; \/\/ Assuming 'response' contains the XML response string XDocument responseDoc = XDocument.Parse(response); var result = responseDoc.Descendants(\"YourResponseElement\").FirstOrDefault()?.Value; \/\/ Adjust as necessary Console.WriteLine(result);landonjameson3 reputationPosted Feb 10, 2025, 9:40 PM EST
This is a serious problem, and I appreciate that you brought it to light fnaf