.Net Remoting을 사용하고 있으며 서버에서 수정 된 원격 객체에 액세스하려고하면 def : 개체가 생성됩니다. 서버에서 생성 한 MRB 객체 클라이언트에 getString()이 호출되면 "Set On Server"가 인쇄됩니다..Net Remoting (C#)의 문제점
현재 클라이언트에서 null 문자열이 표시되므로 클라이언트에서 MRB 개체가 호출 될 때 MRB 개체가 클라이언트에 보내지지 않습니다. 다른 모든 클래스 등을 유감스럽게 생각하지만 그 유일한 방법은 가능한 한 많이 수정했습니다.
내가 실제로 원하는 것은 "서버에 설정"클라이언트가 실행될 때이 인쇄 된 것입니다.
using System;
using System.Runtime.Remoting;
using RemoteType;
namespace SimpleServer
{
class SimpleServer
{
public static MyRemoteObject MRB = null;
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemotingAppServer.exe.config");
MRB = new MyRemoteObject();
MRB.setString("Set on the server");
Console.WriteLine(MRB.getString());
RemotingServices.Marshal((MRB), "MyRemoteObject");
Console.WriteLine("Press return to exit");
Console.ReadLine();
}
}
그리고 .NET 원격 구성의 app.config :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8000" />
</channels>
<service>
<wellknown mode="Singleton"
type="RemoteType.MyRemoteObject, RemoteType"
objectUri="MyRemoteObject" />
</service>
</application>
</system.runtime.remoting>
</configuration>
마지막으로 클라이언트 :
using System;
using System.Runtime.Remoting.Lifetime;
namespace RemoteType
{
public class MyRemoteObject : System.MarshalByRefObject
{
private string sharedString;
public string getString()
{
return sharedString;
}
public void setString(string value)
{
sharedString = value;
}
public MyRemoteObject()
{
Console.WriteLine("MyRemoteObject Constructor Called");
}
public override object InitializeLifetimeService()
{
return null;
}
public string Hello()
{
return "Hello, Welcome to .Net Remoting !";
}
}
여기 알고는 서버입니다
using System;
using System.Runtime.Remoting;
using RemoteType;
namespace SimpleClient
{
class SimpleClient
{
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemoteClient.exe.config");
MyRemoteObject robj = new MyRemoteObject();
Console.WriteLine(robj.Hello() + " " + robj.getString());
Console.ReadLine();
}
}
}
그리고 그 구성 :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name = "SimpleClient">
<client>
<wellknown
type="RemoteType.MyRemoteObject,RemoteType"
url="tcp://localhost:8000/MyRemoteObject"/>
</client>
<channels>
<channel ref="tcp" port="0"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
클라이언트가 실행될 때 클라이언트에 인쇄 된 "서버에 설정"이 나타 났습니까? – daniel
@daniel : 한 번에 서버와 클라이언트를 시작하도록 프로젝트를 설정 했습니까? 그렇다면 클라이언트 코드의 시작 부분에 Thread.Sleep을 추가하는 것이 도움이 될 수 있습니다. –
예, 두 화면의 클라이언트 및 서버에서 "서버에 설정"을 보았습니다. 나는 서버용과 클라이언트 용의 두 가지 솔루션을 가지고있었습니다. 먼저 서버를 시작한 다음 여러 번 클라이언트를 시작했습니다. 모두 똑같은 성공 결과를 얻었습니다. – jmservera