本文介绍了使用委托从客户端到服务器调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,我需要你的帮助,

我必须在客户端程序集上定义一个函数,以便可以使用Delegates从服务器调用它。请有人帮帮我:



Hello Guys, please i need your help,
i have to define a fonction on a client-Assembly so that this can be called from the Server using the Delegates. Please can somebody help me:

/*****************************
 * Interface
/****************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterfaceIntegral
{
    public interface IFunction
    {
        double Adfunc(double x, double y);
    }
}







/*****************************
 * Client
/****************************/

using System;
using InterfaceIntegral;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;


namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {

            TcpChannel chan = new TcpChannel(1984);
            ChannelServices.RegisterChannel(chan, true);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Function), "Function", WellKnownObjectMode.Singleton);
            IAddFunction Objfunc = (IAddFunction )Activator.GetObject(typeof(IAddFunction ), "tcp://localhost:1983/FunctionAdd");
            Console.WriteLine("\n");

            Console.Write(" Value of the AddFunction is: ");
        }
    }
    public class Function : MarshalByRefObject, IFunction
    {
        public double func(double x, double y)
        {
            return  x + y ;
        }
    }
}




/*****************************
 * Server
/****************************/

namespace Server
{
   public class Program
    {
        static void Main(string[] args)
        {
            try
            {
                TcpChannel chan = new TcpChannel(1983);

                ChannelServices.RegisterChannel(chan, true);

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(GaussQuadratur), "GaussQuadratur", WellKnownObjectMode.Singleton);
                Console.WriteLine("**********************************************************************");
                Console.WriteLine("*                    Server Aktiviert                                *");
                Console.WriteLine("**********************************************************************");
                Console.ReadKey();
            }
            catch(ServerException se)
            {
                Console.WriteLine(se.Message);
            }
        }
    }

        public double MyFunktion(double x, double N)
        {
            double epsilon, erg = 0.0d;
            double end = Math.Sqrt(1.0 - Math.Pow(x, 2.0));
            double anf = -end;
            int j;


            IFunction function = (IFunction)Activator.GetObject(typeof(IFunction), "tcp://localhost:1984/Function");
            double h = (end - anf) / ((double)N * 2.0);

            epsilon = anf + h;
            for (j = 0; j < 10; j++)
            {
                erg += 5.0 * function.func(x, (epsilon - h * 4));
                erg += 8.0 * function.func(x, epsilon);
                erg += 5.0 * function.func(x, (epsilon + h * 4));


                epsilon = anf + (2.0 * (double)j + 1.0) * h;
            }

            erg *= h / 9.0;

            return erg;
        }
    }
}



请帮帮我!!


Please helpü me!!

推荐答案

这篇关于使用委托从客户端到服务器调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:47