1
I am trying to consume an external service that receives an xml Soap, but always returns error 500 (Internal server error). But if I test via SOAPUI works normally.
I have tested several types of call and none of it works. Would anyone know what it can be, or how to do it the right way?
in . net core, I created an api to receive the data and convert it into the xml object and call that external service. so I set up the api with xmlformatters
services.AddControllers()
.AddXmlSerializerFormatters()
.AddXmlDataContractSerializerFormatters();
my first attempt was this
httpClient.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
var httpRequest = new HttpRequestMessage()
{
RequestUri = new Uri(apiUrl),
Method = HttpMethod.Post
};
httpRequest.Content = new StringContent(xml.ToString(), Encoding.UTF8, "text/xml");
httpRequest.Headers.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
HttpResponseMessage response = httpClient.SendAsync(httpRequest).Result;
my 2nd attempt was:
HttpResponseMessage response = await httpClient.PostAsync(apiUrl, new StringContent(xml, Encoding.UTF8, "text/xml"));
have tried other ways too. none works.
gave internal error 500 tb
– Guilherme Camarotto
-- Edit -- actually your code works. I did a test of an example flame from any site and it really worked. the problem must be in my upload xml. thanks.
– Guilherme Camarotto