请教一个Remoting 调用的问题
paena 2007-02-02 10:21:13 我写了一个小程序,包括client,server,dll,我的设想是在dll中只有接口,具体的实现在server中完成,client只是调用相关的接口,具体的程序如下:
dll:
// dotnet_dll.h
#pragma once
using namespace System;
namespace dotnet_dll {
public interface class dll_class
{
String^ Sayhello(String^ name);
};
}
server:
#include "stdafx.h"
using namespace System;
#using <system.runtime.remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
namespace dotnet_dll {
public ref class dll_class_inst:System::MarshalByRefObject,dll_class
{
public:
virtual String^ Sayhello(String^ name)
{
return "Hello, " + name;
};
};
}
int main(array<System::String ^> ^args)
{
TcpChannel^ Channel=gcnew TcpChannel(8888);
ChannelServices::RegisterChannel(Channel);
RemotingConfiguration::RegisterWellKnownServiceType( dotnet_dll::dll_class::typeid,"dotnet_dll",WellKnownObjectMode::SingleCall );
Console::WriteLine("Server is running...");
Console::ReadLine();
return 0;
}
client:
dotnet_dll::dll_class^ pObj;
TcpClientChannel^ Channel=gcnew TcpClientChannel();
ChannelServices::RegisterChannel(Channel);
pObj=(dotnet_dll::dll_class^)Activator::GetObject(dotnet_dll::dll_class::typeid,"tcp://192.168.1.111:8888/dotnet_dll");
pObj->Sayhello("World");
以上编译全部都通过了,server也运行起来了,但客户端执行到
pObj->Sayhello("World");
就出问题,我刚接触.net,请教高手能告诉我错在什么地方吗?多谢!