无法部署和使用启用WebORB的C#程序
我曾尝试部署WebORB.NET C#ASP.NET(C#.NET)应用程序,但无法使其正常工作。它将成功运行,但它什么也做不了,我感觉我犯了一些愚蠢的错误。 我有一个Flex客户机,它应该读取来自WebORB服务器的数据,WebORB控制台显示Flex客户机已连接,因此该部分正常。C#.net服务器应用程序不起作用 我已经在下面发布了C#.asp服务器应用程序代码,因为我相信客户端工作正常。此应用程序应捕获运行它的机器的CPU使用情况,并将其发送到WEBORB服务器,以允许Flex客户端进行访问。代码来自WebORB网站上提供的示例 Default.aspx无法部署和使用启用WebORB的C#程序,c#,asp.net,weborb,C#,Asp.net,Weborb,我曾尝试部署WebORB.NET C#ASP.NET(C#.NET)应用程序,但无法使其正常工作。它将成功运行,但它什么也做不了,我感觉我犯了一些愚蠢的错误。 我有一个Flex客户机,它应该读取来自WebORB服务器的数据,WebORB控制台显示Flex客户机已连接,因此该部分正常。C#.net服务器应用程序不起作用 我已经在下面发布了C#.asp服务器应用程序代码,因为我相信客户端工作正常。此应用程序应捕获运行它的机器的CPU使用情况,并将其发送到WEBORB服务器,以允许Flex客户端进行访
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="aspNetCCPU._Default" %>
<%
// Load a new instance of the class
aspNetCCPU.Class1 jiifjio = new aspNetCCPU.Class1();
Response.Write("Class loaded");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Diagnostics;
using System.Timers;
using Weborb.Util;
using Weborb.Messaging.Api.Service;
using Weborb.Messaging.Api;
using Weborb.Messaging.Server.Adapter;
namespace aspNetCCPU
{
public class Class1 : ApplicationAdapter
{
private Timer cpuReadingTimer;
private PerformanceCounter cpuCounter;
// invoked when WebORB for .NET starts up
public override bool appStart(IScope app)
{
bool appStarted = base.appStart(app);
// if application could not start for any reason, do not proceed further
if (!appStarted)
return appStarted;
// initialize performance counter
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
// start thread to get CPU readings
cpuReadingTimer = new Timer(1000);
cpuReadingTimer.Elapsed += new ElapsedEventHandler(cpuReadingTimer_Elapsed);
return appStarted;
}
void cpuReadingTimer_Elapsed(object sender, ElapsedEventArgs e)
{
// ignore timer event, if there are no connected clients to the scope
if (scope.getClients().Count == 0)
return;
// get the CPU reading
float cpuUtilization = cpuCounter.NextValue();
// create an array of values to deliver to the client.
// there is only one value, but the API requires it to be an array
object[] args = new object[] { cpuUtilization };
// get an enumeration of connections to this application
IEnumerator<IConnection> connections = scope.getConnections();
while (connections.MoveNext())
{
IConnection connection = connections.Current;
// invoke client-side function to deliver CPU reading
if (connection is IServiceCapableConnection)
((IServiceCapableConnection)connection).invoke("processCPUReading", args);
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用系统文本;
使用系统诊断;
使用系统计时器;
使用Weborb.Util;
使用Weborb.Messaging.Api.Service;
使用Weborb.Messaging.Api;
使用Weborb.Messaging.Server.Adapter;
名称空间aspNetCCPU
{
公共类Class1:应用程序适配器
{
专用定时器cpuReadingTimer;
私人业绩计数器CPU计数器;
//当.NET的WebORB启动时调用
公共覆盖布尔应用程序启动(IScope应用程序)
{
bool-appStart=base.appStart(app);
//如果应用程序因任何原因无法启动,请不要继续
如果(!appStarted)
返回已启动的应用程序;
//初始化性能计数器
cpuCounter=新性能计数器();
cpuCounter.CategoryName=“处理器”;
cpuCounter.CounterName=“%Processor Time”;
cpuCounter.InstanceName=“_Total”;
//启动线程以获取CPU读数
cpuReadingTimer=新定时器(1000);
cpuReadingTimer.appeased+=新的ElapsedEventHandler(cpuReadingTimer\u appeased);
返回已启动的应用程序;
}
无效cpuReadingTimer_已过(对象发送器,ElapsedEventArgs e)
{
//如果没有连接到作用域的客户端,则忽略计时器事件
if(scope.getClients().Count==0)
返回;
//获取CPU读数
float cpuUtilization=cpuCounter.NextValue();
//创建要传递给客户端的值数组。
//只有一个值,但API要求它是数组
object[]args=新对象[]{cpuUtilization};
//获取此应用程序的连接枚举
IEnumerator connections=scope.getConnections();
while(connections.MoveNext())
{
i连接连接=连接。电流;
//调用客户端函数以提供CPU读取
if(连接为IServiceCapableConnection)
((IServiceCapableConnection)连接)调用(“ProcessCPureReading”,args);
}
}
}
}
Joel--
错误:忘记了,默认情况下,每次调用服务类的任何方法时,都会实例化(由WebORB)服务类的新实例
修复程序:使用属性[ApplicationActivation()]装饰服务类,以便在调用应用程序的整个生命周期中使用相同的服务类实例
有关详细信息,包括示例代码,请参阅
希望有帮助!:-)
吉姆·普拉蒙登
技术传道者
午夜编码器(WebORB的制造商)
附言:我为我的反应缓慢而道歉;我今天第一次发现你的问题。乔尔--
错误:忘记了,默认情况下,每次调用服务类的任何方法时,都会实例化(由WebORB)服务类的新实例
修复程序:使用属性[ApplicationActivation()]装饰服务类,以便在调用应用程序的整个生命周期中使用相同的服务类实例
有关详细信息,包括示例代码,请参阅
希望有帮助!:-)
吉姆·普拉蒙登
技术传道者
午夜编码器(WebORB的制造商)
附言:我为我的反应缓慢而道歉;我今天第一次发现你的问题