Create a C # class library project DLL
Implementation Code:
Using system;
Namespace DLL
{
/// <Summary>
/// Summary of test.
/// </Summary>
[System. serializable]
Public class test
{
Public test ()
{
//
// Todo: add the constructor logic here
//
}
Public String time
{
Get
{
Return datetime. Now. tostring ();
}
}
}
}
Using system;
Using system. IO;
Namespace DLL
{
/// <Summary>
/// API summary.
/// </Summary>
Public class API: system. externalbyrefobject
{
Public API ()
{
//
// Todo: add the constructor logic here
//
}
Public String gettime ()
{
Return new test (). time;
}
Public String [] getdirectories (string path)
{
Return directory. getdirectories (PATH );
}
Public String [] getfiles (string path)
{
Return directory. getfiles (PATH );
}
}
}
Add C # Windows Application Project Server
Implementation Code:
Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using system. runtime. remoting;
Using system. runtime. remoting. channels;
Using system. runtime. remoting. channels. TCP;
Using DLL;
Namespace Server
{
/// <Summary>
/// Summary of form1.
/// </Summary>
Public class form1: system. Windows. Forms. Form
{
/// <Summary>
/// Required designer variables.
/// </Summary>
Private system. componentmodel. Container components = NULL;
Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();
//
// Todo: add Any constructor code after initializecomponent calls
//
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
//
// Form1
//
This. autoscalebasesize = new system. Drawing. Size (6, 14 );
This. clientsize = new system. Drawing. Size (208,150 );
This. Name = "form1 ";
This. Text = "form1 ";
This. Load + = new system. eventhandler (this. form#load );
}
# Endregion
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
}
Private void form1_load (Object sender, system. eventargs E)
{
Tcpchannel Chan = new tcpchannels (7777 );
Channelservices. registerchannel (Chan );
Remotingconfiguration. registerwellknownservicetype (
Type. GetType ("DLL. API, DLL "),
"Test ",
Wellknownobjectmode. singlecall );
}
}
}
Add C # windows application project client
Global. CS code:
Using system;
Using system. runtime. remoting;
Using system. runtime. remoting. channels;
Using system. runtime. remoting. channels. TCP;
Using DLL;
Namespace Client
{
/// <Summary>
/// Summary of Global.
/// </Summary>
Public class global
{
Public global ()
{
//
// Todo: add the constructor logic here
//
}
Public static DLL. API
{
Get
{
Return (DLL. API) activator. getObject (typeof (DLL. API), "TCP: //" + config. host + ":" + config. port + "/test ");
}
}
}
}
Key code of the main form:
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
Channelservices. registerchannel (New tcpchannel ());
}
Private void form1_load (Object sender, system. eventargs E)
{
String [] files = Global. API. getfiles (@ "C:/"); // obtain the file on drive C of the server
}
References: http://support.microsoft.com/default.aspx? SCID = KB; ZH-CN; 307546