几个月前,微软决定更改HttpResponseMessage类.之前,您可以简单地将数据类型传递给构造函数,然后返回包含该数据的消息,但不再是.
现在,您需要使用Content属性来设置消息的内容.问题是它是HttpContent类型,我似乎无法找到将字符串转换为HttpContent的方法.
有谁知道如何处理这个问题?非常感谢.
这是情况.
我正在使用的: - ASP.NET MVC 4 Web API - IIS 7.0来托管应用程序 - C#
我有Web API从Intranet上的远程机器获取性能数据,并且正在测试通过URL调用调用API,这将返回JSON.但是,它必须在返回JSON之前先完成执行.因此,例如,如果我返回10秒的性能监视,我将需要等待10秒才能显示所有数据值.
我想要做的就是让它生效,这样当它每秒读取性能计数器并以JSON显示它时将返回一个值,而不是等待检索所有内容然后立即列出所有内容.我试图使用YIELD关键字来完成此任务,但它仍然无法正常工作.在方法完成之前,JSON不会显示在浏览器中.
以下是存储库方法和协调控制器操作的代码:
从LogDBRepository.cs:
public IEnumerable<DataValueInfo> LogTimedPerfDataLive(string macName, string categoryName, string counterName,
string instanceName, string logName, long? seconds)
{
iModsDBRepository modsDB = new iModsDBRepository();
List<MachineInfo> theMac = modsDB.GetMachineByName(macName);
if (theMac.Count == 0)
yield break;
else if (instanceName == null)
{
if (!PerformanceCounterCategory.Exists(categoryName, macName) ||
!PerformanceCounterCategory.CounterExists(counterName, categoryName, macName))
{
yield break;
}
}
else if (instanceName != null)
{
if (!PerformanceCounterCategory.Exists(categoryName, macName) ||
!PerformanceCounterCategory.CounterExists(counterName, categoryName, macName) || …Run Code Online (Sandbox Code Playgroud) 我知道如何使用System.DirectoryServices网络在服务器上获取这些机器.问题是我想忽略网络上的工作站/计算机,只检索服务器.
如果有人说检查操作系统版本,获取Win NT系列操作系统版本号的问题是每个数字可能对应于服务器和非服务器操作系统(例如NT版本6.1同时指向Win 7和Win Server 2008 R2).
这是我的基础测试类:
namespace Project1
{
class Class1
{
public static void Main(string[] args)
{
List<string> list = Class1.GetComputersOnNetwork();
}
public static List<string> GetComputersOnNetwork()
{
string fileName = "networkcomputers.txt";
// Delete the file if it exists.
if (System.IO.File.Exists(fileName))
{
System.IO.File.Delete(fileName);
}
// Create the file.
System.IO.FileStream fs = System.IO.File.Create(fileName, 1024);
StreamWriter strwr = new StreamWriter(fs);
int i = 0;
List<string> list = new List<string>();
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry computers in root.Children)
{ …Run Code Online (Sandbox Code Playgroud)