Server:
//类
namespace RemotingServer
{
public class Class1: MarshalByRefObject
{
public double CalcSalesTax(double SalesPrice)
{
return SalesPrice * 0.01;
}
}
}
//服务器端控制台
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using RemotingServer;
namespace TestConsoleApp
{
public class Startup
{
static void Main(string[] args)
{ RemotingConfiguration.Configure(@"E:\_Projects\DotNet\TestConsoleApp\TestConsoleApp\RemotingConfig.cfg",true);
Console.WriteLine("输入任意键退出");
Console.ReadKey();
}
}
}
{
public class Class1: MarshalByRefObject
{
public double CalcSalesTax(double SalesPrice)
{
return SalesPrice * 0.01;
}
}
}
//服务器端控制台
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using RemotingServer;
namespace TestConsoleApp
{
public class Startup
{
static void Main(string[] args)
{ RemotingConfiguration.Configure(@"E:\_Projects\DotNet\TestConsoleApp\TestConsoleApp\RemotingConfig.cfg",true);
Console.WriteLine("输入任意键退出");
Console.ReadKey();
}
}
}
服务器端配置文件: RemotingConfig.cfg
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="Server">
<service>
<!--
<wellknown type="空间名.类名,程序集名" objectUri="空间名.类名"
mode="Singleton" />
<wellknown ....="" />
-->
<wellknown mode="SingleCall" objectUri="RemotingServer.Class1"
type="RemotingServer.Class1,RemotingServer"/>
</service>
<channels>
<channel ref="tcp" port="9999" >
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
<system.runtime.remoting>
<application name="Server">
<service>
<!--
<wellknown type="空间名.类名,程序集名" objectUri="空间名.类名"
mode="Singleton" />
<wellknown ....="" />
-->
<wellknown mode="SingleCall" objectUri="RemotingServer.Class1"
type="RemotingServer.Class1,RemotingServer"/>
</service>
<channels>
<channel ref="tcp" port="9999" >
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Client:
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
namespace RemotingClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalc_Click(object sender, EventArgs e)
{
RemotingServer.Class1 cls = new RemotingServer.Class1();
double dRes= cls.CalcSalesTax(double.Parse(this.textBox1.Text.Trim()));
MessageBox.Show(dRes.ToString("###,##0.00"));
}
private void Form1_Load(object sender, EventArgs e)
{
RemotingConfiguration.Configure(@"E:\_Projects\DotNet\TestConsoleApp\RemotingClient\ClientConfig.cfg", true);
}
}
}
using System.Runtime.Remoting.Channels;
namespace RemotingClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalc_Click(object sender, EventArgs e)
{
RemotingServer.Class1 cls = new RemotingServer.Class1();
double dRes= cls.CalcSalesTax(double.Parse(this.textBox1.Text.Trim()));
MessageBox.Show(dRes.ToString("###,##0.00"));
}
private void Form1_Load(object sender, EventArgs e)
{
RemotingConfiguration.Configure(@"E:\_Projects\DotNet\TestConsoleApp\RemotingClient\ClientConfig.cfg", true);
}
}
}
Client配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="Client">
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
<client>
<!--
<wellknown type="空间名.类名, 程序集名" url="tcp://ip:9999/空间名.类名" />
<wellknown ....="" />
-->
<wellknown type="RemotingServer.Class1, RemotingServer" url="tcp://localhost:9999/RemotingServer.Class1" />
</client>
</application>
</system.runtime.remoting>
</configuration>
<configuration>
<system.runtime.remoting>
<application name="Client">
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
<client>
<!--
<wellknown type="空间名.类名, 程序集名" url="tcp://ip:9999/空间名.类名" />
<wellknown ....="" />
-->
<wellknown type="RemotingServer.Class1, RemotingServer" url="tcp://localhost:9999/RemotingServer.Class1" />
</client>
</application>
</system.runtime.remoting>
</configuration>