How to receive a Webapi data parameter

Asked

Viewed 39 times

0

I receive an xml in my webAPI and deserializo it.

What I did, I took the exact XML template that I’m going to receive and I call my service locally, just for the test effect. So far so good, I can get the fields I need. However, when I publish, in the documentation of who will send me, they inform that they will pass this same XML, but within a date parameter. I would like to know, how to prepare my Url to understand and capture xml with this parameter. Until then, I do the requisition, send via body, but do not use it.

it will probably come data= xml with the contents.

namespace WsCliMotoristas.Controllers
{
    public class XmlController : ApiController
    {
       [HttpPost]
        public void Post(HttpRequestMessage xml)
        {
            string idumov, identificadoralternativo;
            idumov = "";
            identificadoralternativo = "";
            try
            {

                string body = xml.Content.ReadAsStringAsync().Result;
                var Schedules = System.Xml.Linq.XDocument.Parse(body);

                foreach (var elementos in Schedules.Root.Elements())
                {
                    if (elementos.Name == "alternativeIdentifier")
                    {
                         identificadoralternativo = elementos.Value;


                    }

                    foreach (var historicos in elementos.Elements())
                    {
                        if (historicos.Name == "activityHistory")
                        {
                            idumov = historicos.FirstAttribute.Value;

                        }

                    }
                }

                GetEntrega entrega = new GetEntrega();

                entrega.GeraEntregaAsync(idumov);
            }

            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }

        }
    }
}
  • Friend, you may have the xml format, but all the indications are you are receiving a string. It’s not clear enough, but as far as I can tell, the consumer of your api wants to send a json by passing this string in an attribute called date.

  • " date parameter" what does that necessarily mean? a date named object? it is possible to edit and put the documentation from where you received this information?

  • The body of the request it makes in my service will come like this: data= XML content

  • In my test, consuming my service, I simply send the xml in the body, without any parameter. Body = XML content / the client sends me this way: body data= xml content

  • If I do not prepare my service to wait for this parameter called date I will have an error. I’m still finishing up, so I didn’t publish it and I tested it directly on his call, but it’s clear I’ll have an error.

  • Post an example of this request that you should receive

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.