0

my c# code to call webservice -

        var content = new StringContent(req.Body.ToString(), Encoding.UTF8, "application/xml"); ;
        HttpClient httpClient = new HttpClient();
        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://mydemo.com/service.asmx?pk=listCustomer");

        var byteArray = Encoding.ASCII.GetBytes("username:password");

        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

        request.Content = content;
        request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");
        HttpResponseMessage response = await httpClient.SendAsync(request);

        // getting 500 error in response data at root level invalid

in postman i call this azure function to pass xml input.

xml input format is -

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <listCustomer xmlns="http://tempuri.org/">
      <id>KH001</id>
      <fromDate>01/01/2018</fromDate>
      <toDate>01/01/2020</toDate>
    </listCustomer>
  </soap:Body>
</soap:Envelope>
Neo
  • 15,491
  • 59
  • 215
  • 405
  • 1
    Can you try reading the XML body using this? `var content = await new StreamReader(req.Body).ReadToEndAsync();` – Kamesh Apr 24 '20 at 05:50

1 Answers1

1

I test function on the local with postman, below is my code. Maybe you could have a try.

public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");



            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();


            return new ContentResult { Content = requestBody, ContentType = "application/xml" };
        }

And the content type would be right.

enter image description here

enter image description here

George Chen
  • 13,703
  • 2
  • 11
  • 26