1

WebORB .NET C# ASP.NET (C#.NET) アプリケーションをデプロイしようとしましたが、動作させることができません。正常に実行されますが、何も行われず、ばかげた間違いを犯しているような気がします。WebORB サーバーからのデータを読み取る必要がある Flex クライアントがあり、WebORB コンソールは、Flex クライアントが接続されていることを示しているため、その部分は問題ありません。C#.net サーバー アプリケーションが機能していません。

クライアントが正常に動作すると思われるため、C#.asp サーバー アプリケーション コードを以下に掲載しました。このアプリケーションは、実行中のマシンの CPU 使用率を取得し、それを WEBORB サーバーに送信して、Flex クライアントによるアクセスを許可する必要があります。コードは、WebORB Web サイトで提供されている例からのものです。

デフォルト.aspx

<%@ 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);
            }
        }
    }
}
4

1 に答える 1

1

ジョエル --

間違い: デフォルトでは、サービス クラスの新しいインスタンスが、そのメソッドのいずれかが呼び出されるたびに (WebORB によって) インスタンス化されることを忘れています。

修正: 属性 [ApplicationActivation()] を使用してサービス クラスをデコレートし、サービス クラスの同じインスタンスが呼び出しアプリケーションの存続期間にわたって使用されるようにします。

サンプル コードを含む詳細については、http://blog.themidnightcoders.com/index.php/2010/10/28/server-side-cpu-usage-in-weborbを参照してください。

それが役立つことを願っています! :-)

Jim Plamondon テクノロジー エバンジェリスト The Midnight Coders (WebORB のメーカー)

PS: 返信が遅くなって申し訳ありません。今日、あなたの質問を初めて見つけました。

于 2010-10-28T19:51:30.240 に答える