我有 ac# 控制台应用程序计划在 Win 2003 服务器上运行,读取磁盘空间、cpu 使用率等值。
现在我想在 aspx 页面上在线或实时显示这些值。
到目前为止,这是我的(非工作)尝试:
WCF 服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace ServerMonitoring
{
public class Service1 : IService1
{
public void InsertDataValues(DataValues server)
{
FreeDiskSpace = server.FreeDiskSpace;
Data.FreeDiskSpace = FreeDiskSpace;
}
[DataMember]
public decimal FreeDiskSpace
{
get { return Data.FreeDiskSpace; }
set { Data.FreeDiskSpace = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace ServerMonitoring
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void InsertDataValues(DataValues server);
}
[DataContract]
public class DataValues
{
[DataMember]
public decimal FreeDiskSpace;
/*
[DataMember]
public decimal TotalDiskSpace;
*/
}
}
尝试从后面的代码更新文本框:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ServerMonitoring
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onchange", "DefaultValue();");
HiddenFieldFreeDiskSpace.Value = Data.FreeDiskSpace.ToString();
}
}
}
默认.aspx:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="ServerMonitoring._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="head">
<script type="text/javascript">
function DefaultValue() {
var data = $('#<%=HiddenFieldFreeDiskSpace.ClientID%>').val();
var txt1 = document.getElementById("TextBox1");
txt1.setAttribute("value", data);
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<div class="extra-wide-column">
<h2>
FIC Server Monitoring Services
</h2>
<br />
<br />
<br />
<h3>System</h3>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:HiddenField runat="server" ID="HiddenFieldFreeDiskSpace" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
要写入文本框的值来自我的控制台应用程序,并引用了我的 WCF 服务
static void UpdateList(string columnName, decimal diskSpaceValue)
{
Service1 serv = new Service1();
DataValues dv = new DataValues();
dv.FreeDiskSpace = diskSpaceValue;
serv.InsertDataValues(dv);
}
但是,该值不会发送到asp页面
BR,同行