111,130
社区成员
发帖
与我相关
我的任务
分享
// 服务端
TcpChannel^ channel = gcnew TcpChannel(8000);
ChannelServices::RegisterChannel(channel, true);
// 注册远程对象
RemotingConfiguration::ApplicationName = "RemotingApplication";
RemotingConfiguration::RegisterWellKnownServiceType( Type::GetType( "CommonService.CommonSvice, CommonService" ), "CommonSvice", WellKnownObjectMode::SingleCall );
CommonService::CommonSvice::DateSetEventHandler += gcnew CommonService::DateSetEventHandler( this, &Form1::OnDsRevice );
listBox1->CheckForIllegalCrossThreadCalls = false;
//
private: System::Void OnDsRevice(DataSet^ DsRevice){
// 收到DATASET后,在LISTBOX上显示一行字符串
listBox1->Items->Add( "OK!DataSet" );
}
// 客户端
TcpClientChannel^ channelClient = gcnew TcpClientChannel();
ChannelServices::RegisterChannel (channelClient, true);
RemotingConfiguration::RegisterWellKnownClientType( Type::GetType("CommonService.CommonSvice, CommonService"), "tcp://localhost:8000/CommonSvice" );
obj = gcnew CommonService::CommonSvice();
// 按钮按下时:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
DataSet^ DStemp = gcnew DataSet();
obj->SendDataSet(DStemp);
}
// 接口
namespace CommonService {
public delegate void DateSetEventHandler(DataSet^);
public interface class IFaxBusiness
{
void SendDataSet(String^);
};
public ref class CommonSvice : public MarshalByRefObject
{
// TODO: 在此处添加此类的方法
public:static event DateSetEventHandler^ DateSetEventHandler;
public: void SendDataSet(DataSet^ DsTemp)
{
DateSetEventHandler(DsTemp);
}
public: virtual Object^ InitializeLifetimeService() override
{
return nullptr;
}
};
}

CommonService::IFaxBusiness^ watch = (CommonService::IFaxBusiness^)Activator::GetObject( Type::GetType("CommonService.CommonSvice, CommonService"), "tcp://localhost:8000/CommonSvice.soap");
CommonService::EventWrapper^ wrapper = gcnew CommonService::EventWrapper();
wrapper->LocalBroadCastEvent += gcnew CommonService::BroadCastEventHandler(this, &Form1::BroadCastingMessage);
watch->BroadCastEvent += gcnew CommonService::BroadCastEventHandler(this, &wrapper->BroadCasting); // 这里报错:“&”: 绑定成员函数表达式上的非法操作