请教关于 remoting的问题,请帮帮忙.

seekingyou 2003-10-02 12:17:13
我看过.net framework关与remoting 的例子,都是首先要把例如ServiceClass.cs 等compile为dll文件,然后server.exe才可以用,我现在把server.cs放在vs.net2003里,只有引用ServiceClass.dll才可以通过.

但是如果我只是在vs.net2003引入ServiceClass.cs(没有引用ServiceClass.dll),这样做我是想可以给ServiceClass.cs里面的参数付值,但结果就说值不能为空,请问怎样可以在server端给 ServiceClass.cs(或ServiceClass.dll)里的参数付值?
...全文
30 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
godenjing 2003-10-27
  • 打赏
  • 举报
回复
老大你调用过HelloMethod 函数吗?
zhehui 2003-10-09
  • 打赏
  • 举报
回复
我觉得一定要做成dll控件。然后去引用控件中的内容。
在winform开发中是这么做。
seekingyou 2003-10-09
  • 打赏
  • 举报
回复
shixueli(渴望成功),你在最后是给p.C一个string,是在server.exe里给的,我要的C是从serviceClass.dll传过来的.
shixueli 2003-10-03
  • 打赏
  • 举报
回复
天啊,你的写法有问题:
-->
如果用属性:
在ServiceClass.dll里面,把public string c;改成:private string c;
然后添加代码:
public string C
{
get{return c;}
}

对于server.exe,你的处理有问题:
private void button1_Click(object sender, System.EventArgs e)
{
HelloServer p = new HelloServer();
MessageBox.Show(p.c);
}
应该是:
private void button1_Click(object sender, System.EventArgs e)
{
HelloServer p = new HelloServer();
p.C="my name is shixueli";
MessageBox.Show(p.C);
}
seekingyou 2003-10-03
  • 打赏
  • 举报
回复
up
seekingyou 2003-10-02
  • 打赏
  • 举报
回复
shixueli(渴望成功) ,谢谢你,你可以帮我写一写出来?例如怎样把ServiceClass.dll里的string name传给server.exe里的MessageBox.Show(p.c)?
shixueli 2003-10-02
  • 打赏
  • 举报
回复
一个方法是通过public static string name的形式来,这样两个类的对象都能够看到,
否则,通过调用函数以参数的形式穿过去,还有就是,实例化对象,给属性赋值
seekingyou 2003-10-02
  • 打赏
  • 举报
回复
up
gOODiDEA 2003-10-02
  • 打赏
  • 举报
回复
用属性啊,你的代码贴出来
seekingyou 2003-10-02
  • 打赏
  • 举报
回复
ServiceClass.dll是这样的:

using System;

namespace RemotingSamples {

public class ForwardMe : MarshalByRefObject {

public void CallMe(String text)
{
Console.WriteLine(text);
}
}
public class HelloServer : MarshalByRefObject {

public string c;
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}

public String HelloMethod(string name,ForwardMe obj)
{

obj.CallMe("Regards from the server");
Console.WriteLine("Hello.HelloMethod : {0}", name);
c=name;

return String.Format("Hi there {0}",c);
}
}
}

我想要的是把ServiceClass.dll里面的c的值(经过Clieng符值给它之后)传到server.exe里的MessageBox.Show(p.c);

但它只能传c原来的值null,请问怎样把c=name的值传到server.exe?
seekingyou 2003-10-02
  • 打赏
  • 举报
回复
gOODiDEA(无语),谢谢你,我的server.exe是这样的:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters;
using RemotingSamples;
namespace RemotingSamples
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
RemotingSamples.HelloServer f;
public string ff="ere";

// private WindowsApplication6.Form1.
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;

IDictionary props = new Hashtable();
props["port"] = 8085;

TcpChannel chan = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("RemotingSamples.HelloServer,Share"), "SayHello", WellKnownObjectMode.SingleCall);

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void InitializeComponent()
{
........
}


private void button1_Click(object sender, System.EventArgs e)
{
HelloServer p = new HelloServer();
MessageBox.Show(p.c);
}
}


}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧