[英]Remoting in C# not working
我正在學習在.NET中使用遠程處理。 我已經構建了一個小的應用程序,可以完成基本的hello world工作。 RemoteObject的代碼是:
public class MyRemoteObjectClass:MarshalByRefObject
{
public MyRemoteObjectClass()
{
Console.WriteLine("Remote object created");
}
//return message reply
public String ReplyMessage(String msg)
{
Console.WriteLine("Client : " + msg);//print given message on console
return "Server : Yeah! I'm here";
}
}
服務器類的代碼是:
class MyServerClass
{
public MyServerClass()
{
}
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemotingSettings_Server.xml",false);
Console.WriteLine("server activated");
Console.ReadLine();
}
}
客戶端類的源代碼為:
class MyClientAppClass
{
static void Main(string[] args)
{
RemotingConfiguration.Configure("ClientSettings.xml",false);
Console.WriteLine("Settings read successfully");
MyRemoteObjectClass remObject = (MyRemoteObjectClass)Activator.GetObject(typeof(MyRemoteObject.MyRemoteObjectClass),"http://localhost:8989/MyRemoteObjectClass",WellKnownObjectMode.Singleton);
if (remObject == null)
Console.WriteLine("cannot locate server");
else
{ String res = remObject.ReplyMessage("You there?"); Console.WriteLine(res); Console.ReadLine(); }
}
}
我的服務器和客戶端的配置文件分別是:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="Singleton"
type="MyRemoteObject.MyRemoteObjectClass, MyRemoteObjectClass"
objectUri="MyRemoteObjectClass.rem"
/>
</service>
<channels>
<channel ref="http" port="8989"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
客戶:
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown
type="MyRemoteObject.MyRemoteObjectClass, MyRemoteObjectClass"
url="http://localhost:8989/MyRemoteObjectClass.rem"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>
我首先為遠程對象構建了DLL,然后將DLL復制到了服務器和客戶端exe位置。 我先運行服務器,然后運行客戶端。 服務器已實例化,但客戶端程序出現異常,提示“遠程處理異常:找不到請求的服務”。
請幫助我解決此問題,這可能是一個清晰學習遠程處理概念的好地方。
謝謝,拉克什。
檢查您的配置文件-區分大小寫。 例如,“ objecturi”應為“ objectUri”。
停用防火牆。 如果這樣可以工作,請重新激活防火牆並添加適當的例外。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.