저는 Server-Application과 Client-Application간에 통신 할 수 있기를 원합니다. 두 응용 프로그램 모두 C#/WPF로 작성됩니다. 인터페이스는 두 응용 프로그램 모두에 대한 참조가있는 별도의 DLL에 있습니다.다른 프로세스에 메시지 보내기
Serializer<IDataInfo> serializer = new Serializer<IDataInfo>();
IDataInfo dataInfo = new DataInfo(HEADERBYTES, CONTENTBYTES);
Process clientProcess = Process.Start("Client.exe", serializer.Serialize(dataInfo));
클라이언트 응용 프로그램이 가져옵니다
이public interface IDataInfo
{
byte[] Header { get; }
byte[] Data { get; }
}
이 서버 응용 프로그램은 다음과 같은 코드로 클라이언트를 호출 인터페이스 - DLL에
처럼 보이는 IDataInfo 인터페이스입니다 서버로부터의 메시지 :Serializer<IDataInfo> serializer = new Serializer<IDataInfo>();
IDataInfo dataInfo = serializer.Deserialize(string.Join(" ", App.Args));
Serializer-Class는 단지 일반적인 c입니다. lass는 Soap-Formatter를 사용하여 직렬화/역 직렬 변환을 수행합니다. 코드는 다음과 같습니다.
public class Serializer<T>
{
private static readonly Encoding encoding = Encoding.Unicode;
public string Serialize(T value)
{
string result;
using (MemoryStream memoryStream = new MemoryStream())
{
SoapFormatter soapFormatter = new SoapFormatter();
soapFormatter.Serialize(memoryStream, value);
result = encoding.GetString(memoryStream.ToArray());
memoryStream.Flush();
}
return result;
}
public T Deserialize(string soap)
{
T result;
using (MemoryStream memoryStream = new MemoryStream(encoding.GetBytes(soap)))
{
SoapFormatter soapFormatter = new SoapFormatter();
result = (T)soapFormatter.Deserialize(memoryStream);
}
return result;
}
}
여기까지 모든 것이 정상적으로 작동합니다. 서버는 클라이언트를 생성하고 클라이언트는 IDataInfo
-Object에 대한 인수를 deserialize 할 수 있습니다.
이제 서버에서 실행중인 클라이언트로 메시지를 보내고 싶습니다. Interface DLL에 IClient-Interface를 도입했습니다. void ReceiveMessage(string message);
MainWindow.xaml.cs가 IClient-Interface를 구현하고 있습니다.
내 질문 이제 프로세스 개체가있을 때 내 서버에서 IClient 개체를 가져올 수 있습니다. 내가 Activator.CreateInstance
에 대해 생각했지만, 나는 이것을 수행하는 방법을 모른다. 나는 IClient를 Process of Handle으로 얻을 수 있다고 확신하지만, 어떻게해야할지 모르겠다.
아이디어가 있으십니까?
어떤 종류의 의사 소통 체계를 사용해야합니다. WCF에서 읽으십시오. –