日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

remoteing2

發布時間:2023/11/30 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 remoteing2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
此示例主要演示了net remoting,其中包含一個服務器程序Server.exe和一個客戶端程序CAOClient.exe。客戶端程序會通過http channel調用服務器端RemoteType.dll的對象和方法。 服務器端的代碼文件由下圖所述: Server.cs源代碼 : using System;
using System.Runtime.Remoting;
public class Server{
public static void Main(string[] Args){
// Load the configuration file
RemotingConfiguration.Configure("server.exe.config");
Console.WriteLine("The server is listening. Press Enter to exit....");
Console.ReadLine();
Console.WriteLine("GC'ing.");
GC.Collect();
GC.WaitForPendingFinalizers();
}
}

Server.exe.config源代碼:

<SYSTEM.RUNTIME.REMOTING
<APPLICATION>
<SERVICE>
<ACTIVATED type="ClientActivatedType, RemoteType">
</SERVICE>
<CHANNELS>
<CHANNEL ref="http" port="8088">
</CHANNELS>
</APPLICATION>
</SYSTEM.RUNTIME.REMOTING
</CONFIGURATION> RemoteType.cs源代碼: using System;
using System.Runtime.Remoting.Lifetime;
using System.Security.Principal;
public class ClientActivatedType : MarshalByRefObject{
private int i;
// override the lease settings for this object
public override Object InitializeLifetimeService(){
return null;
}
public string RemoteMethod(){
// announce to the server that we've been called.
Console.WriteLine("ClientActivatedType.RemoteMethod called.");
// report our client identity name
i=this.GetHashCode();
return "RemoteMethod called. " + i;
}
public string RemoteMethod1(){
return "RemoteMethod1 called. " + i;
}
} 客戶端代碼文件由下圖所示:

?

CAOClient.cs源代碼: using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
public class Client{
public static void Main(string[] Args){
// Load the configuration file
RemotingConfiguration.Configure("CAOclient.exe.config");
ClientActivatedType CAObject = new ClientActivatedType();
Console.WriteLine("Client-activated object: " + CAObject.RemoteMethod());
Console.WriteLine("Client-activated object: " + CAObject.RemoteMethod1());
Console.WriteLine("Press Enter to end the client application domain.");
Console.ReadLine();
}
} CAOClient.exe.config源代碼: <CONFIGURATION>
<SYSTEM.RUNTIME.REMOTING
<APPLICATION>
<CLIENT url="http://localhost:8088">
<ACTIVATED type="ClientActivatedType, RemoteType">
</CLIENT>
<CHANNELS>
<CHANNEL ref="http" port="0">
</CHANNELS>
</APPLICATION>
</SYSTEM.RUNTIME.REMOTING
</CONFIGURATION>
OK,編譯以上代碼文件: 使用“Visual Studio .net Command Prompt="分別編譯上述文件: csc /target:library RemoteType.cs
csc Server.cs
csc –reference:RemoteType.dll CAOClient.cs
您會看到三個輸出文件:RemoteType.dll, Server.exe 和 CAOClient.exe。
運行Remoting程序
在命令行方式下啟動:Server.exe
在命令行方式下啟動:CAOClient.exe

總結

以上是生活随笔為你收集整理的remoteing2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。