Consume ASP.Net Web API in Smart Device application

297 Views Asked by At

I have this Smart Device application that is going to run in a Zebra MC9200 pocket pc (with Windows CE 7).

I have already made the UI without any problems, and now I need to consume my ASP.Net Web API on the application, so I can get and post data on our database.

My application is a Smart Device Application (for Windows CE) and was developed on a Windows 7 virtual machine, using Visual Studio 2008 and .NET Compact Framework 3.5.

My ASP.Net Web API was developed in my Windows 10 host machine, using Visual Studio 2019 and .Net Framework 4.7.2 and is hosted on IIS Express, distributed through the enterprise intranet.

Our database is SQL Server 2014 (which means I cannot develop a web service directly in my VS2008 application).

Searching on the web I've came with the following code:

    try
        {
            string url = "*<my api url>*";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.Accept = "application/xml";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            response.ContentType = "application/xml";
            Stream stream = response.GetResponseStream();

            using (XmlReader reader = XmlReader.Create(new StreamReader(stream)))
            {
                var doc = XDocument.Load(reader);
                MessageBox.Show(doc.ToString());
            }
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }

but when I'm debugging my application, I receive a NotImplementedException when the debugger tries to execute the response.ContentType = "application/xml"; line of this method.

Anyone has any ideas about how to fix this exception? Or maybe another way to retrieve the data from the api, maybe using JSON.

0

There are 0 best solutions below