📄 ex-19-04
字号:
// Example 19-04: The remoting Calculator client
namespace Programming_CSharp
{
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
public class CalcClient
{
public static void Main()
{
int[] myIntArray = new int[3];
Console.WriteLine("Watson, come here I need you...");
// create an Http channel and register it
// uses port 0 to indicate won't be listening
HttpChannel chan = new HttpChannel(0);
ChannelServices.RegisterChannel(chan);
// get my object from across the http channel
MarshalByRefObject obj =
(MarshalByRefObject) RemotingServices.Connect
(typeof(Programming_CSharp.ICalc),
"http://localhost:65100/theEndPoint");
try
{
// cast the object to our interface
Programming_CSharp.ICalc calc =
obj as Programming_CSharp.ICalc;
// use the interface to call methods
double sum = calc.Add(3.0,4.0);
double difference = calc.Sub(3,4);
double product = calc.Mult(3,4);
double quotient = calc.Div(3,4);
// print the results
Console.WriteLine("3+4 = {0}", sum);
Console.WriteLine("3-4 = {0}", difference);
Console.WriteLine("3*4 = {0}", product);
Console.WriteLine("3/4 = {0}", quotient);
}
catch( System.Exception ex )
{
Console.WriteLine("Exception caught: ");
Console.WriteLine(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -