我有这个智能设备应用程序,它将在 Zebra MC9200 袖珍电脑(使用 Windows CE 7)中运行。
我已经制作了 UI 没有任何问题,现在我需要在应用程序上使用我的 ASP.Net Web API,这样我就可以在我们的数据库上获取和发布数据。
我的应用程序是一个智能设备应用程序(适用于 Windows CE),是在 Windows 7 虚拟机上使用 Visual Studio 2008 和 .NET Compact Framework 3.5 开发的。
我的 ASP.Net Web API 是在我的 Windows 10 主机上开发的,使用 Visual Studio 2019 和 .Net Framework 4.7.2 并托管在 IIS Express 上,通过企业 Intranet 分发。
我们的数据库是 SQL Server 2014(这意味着我不能直接在我的 VS2008 应用程序中开发 Web 服务)。
在网上搜索我得到了以下代码:
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);
}
但是当我调试我的应用程序时,当调试器尝试执行response.ContentType = "application/xml";时,我会收到 NotImplementedException。此方法的行。
有人对如何解决此异常有任何想法吗?或者也许是另一种从 api 检索数据的方法,可能使用 JSON。