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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterfaceIntegral
{
public interface IFunction
{
double Adfunc(double x, double y);
}
}
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 ;
}
}
}
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!!