Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

httpclient soap request c#

public async Task<int> AddNumbersAsync(Uri uri, int a, int b)
{
    var soapString = this.ConstructSoapRequest(a, b);
    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Add("SOAPAction", "http://CalculatorService/ICalculatorService/Add");
        var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
        using (var response = await client.PostAsync(uri, content))
        {
            var soapResponse = await response.Content.ReadAsStringAsync();
            return this.ParseSoapResponse(soapResponse);
        }
    }
}

private string ConstructSoapRequest(int a, int b)
{
    return String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
    <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">
        <s:Body>
            <Add xmlns=""http://CalculatorService/"">
                <a>{0}</a>
                <b>{1}</b>
            </Add>
        </s:Body>
    </s:Envelope>", a, b);
}

private int ParseSoapResponse(string response)
{
    var soap = XDocument.Parse(response);
    XNamespace ns = "http://CalculatorService/";
    var result = soap.Descendants(ns + "AddResponse").First().Element(ns + "AddResult").Value;
    return Int32.Parse(result);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: topdown unity 
Csharp :: unity 2d movement 
Csharp :: how to change the axis of a Vector3 variable 
Csharp :: linux command line switch statement 
Csharp :: how unsort the data table options 
Csharp :: c# search string array 
Csharp :: blazor onchange event not firing with inputselect 
Csharp :: this in unity 
Csharp :: c# array 
Csharp :: unity vscode no autocomplete 
Csharp :: unity RemoveComponent 
Csharp :: check if animation is playing unity 
Csharp :: c# print exception stack trace 
Csharp :: how to write int array to console c# 
Csharp :: how to convert int to float in c# 
Csharp :: unity reverse string 
Csharp :: https request c# 
Csharp :: c# winforms textbox select text 
Csharp :: unity event 
Csharp :: c# reflection resize array 
Csharp :: c# save pdf to folder 
Csharp :: 2d rotation unity 
Csharp :: c# int array length 
Csharp :: wpf mouse over style trigger 
Csharp :: c# bitmap to array byte 
Csharp :: c# mongodb update multiple fields 
Csharp :: change image of button c# 
Csharp :: unity editor script 
Csharp :: c# and in if statement 
Csharp :: creating a streamwiter file C# 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =