0

I have very limited exprerience in MVC, WebAPI,C# etc. I was asked to create a controller that contains a method that receives an HttpRequest (XML) and responds with back with an HttpResponse

I have come up to this state and I am confused:

 [HttpPost]
    [Consumes("application/xml")]
    public async HttpResponseMessage ChannelUpload(HttpRequestMessage request)
    {
        using (var reader = new StreamReader(
        request.Body,
        encoding: Encoding.UTF8,
        detectEncodingFromByteOrderMarks: false)
        )
        {
            string bodyString = await reader.ReadToEndAsync();

            string confirmation = ImportRequest(bodyString);

            //Response
            return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(confirmation) };
        }
    }
  • I do not know whether the parameter of the method is the correct (is HttpRequest valid?).

  • I do not know how to respond (CreateResponse() is not found)

Thank you in advance!

PanosPlat
  • 940
  • 1
  • 11
  • 29
  • 1
    This is essentially the very basics of how MVC works, you will get far more benefit by running through some tutorials than asking a question like this here. – DavidG Jan 05 '21 at 11:41
  • Thanx. I am trying to locate a tutorial in Google "c# receive HttpRequest" etc but I found nothing that seems near my need. As I said, I have very limited knowledge of C#. I am an SQL,Powerbuilder developer. If you have any link handy, I would be grateful – PanosPlat Jan 05 '21 at 11:45

0 Answers0