首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法部署和使用启用WebORB的C#程序

无法部署和使用启用WebORB的C#程序
EN

Stack Overflow用户
提问于 2010-09-17 09:41:13
回答 1查看 517关注 0票数 1

我尝试过部署一个WebORB .NET C# ASP.NET (C#.NET)应用程序,但是我无法让它工作。它会成功运行,但什么也做不了,我觉得我在犯一些愚蠢的错误。我有一个Flex,它应该读取来自WebORB服务器的数据,而WebORB控制台显示Flex客户机是连接的,所以这个部分很好。C#.net服务器应用程序不起作用。

我在下面发布了C#.asp服务器应用程序代码,因为我认为客户端工作正常。这个应用程序应该捕获它正在运行的机器的CPU使用情况,并将其发送到WEBORB服务器以允许Flex客户端访问。代码来自WebORB网站上提供的一个示例。

Default.aspx

代码语言:javascript
复制
<%@ 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

代码语言:javascript
复制
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);
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-28 19:51:30

乔尔--

错误:忘记默认情况下,每次调用服务类的任何方法时都会实例化服务类的一个新实例(由WebORB执行)。

Fix:用属性ApplicationActivation()装饰服务类,以便在调用应用程序的整个生命周期中使用服务类的相同实例。

有关详细信息,包括示例代码,请参见http://blog.themidnightcoders.com/index.php/2010/10/28/server-side-cpu-usage-in-weborb

希望这会有所帮助!

吉姆·普拉蒙登技术布道者,午夜编码者(WebORB的制造者)

P.S.:我为我的答复太慢而道歉;我今天第一次发现你的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3734198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档