i want able communicate between server-application , client-application. both applications written in c#/wpf. interfaces located in separate dll both applications have reference it.
in interface-dll idatainfo-interface looks like:
public interface idatainfo { byte[] header { get; } byte[] data { get; } }
the server-application calls client following code:
serializer<idatainfo> serializer = new serializer<idatainfo>(); idatainfo datainfo = new datainfo(headerbytes, contentbytes); process clientprocess = process.start("client.exe", serializer.serialize(datainfo));
the client-applications gets message server by:
serializer<idatainfo> serializer = new serializer<idatainfo>(); idatainfo datainfo = serializer.deserialize(string.join(" ", app.args));
the serializer-class generic class uses soap-formatter serialize/deserialze. code looks like:
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; } }
until here works fine. server creates client , client can deserialize it's argument idatainfo
-object.
now want able send message server running client. introduced iclient-interface in interface-dll method void receivemessage(string message);
the mainwindow.xaml.cs implementing iclient-interface.
my question how can iclient-object in server, when have process-object. thought activator.createinstance
, have no clue how this. i'm pretty sure can iclient handle of process, don't know how.
any idea?
as other posts mention common way create service, keep more simple consider @ servicestack. afaik servicestack used on stackoverflow
there course on pluralsight
servicestack easy host in .net dll (without iis , on) , doesn't have configuration complexity of wcf.
also endpoints available soap , rest without need configure anything
for example defines hello world service
public class helloservice : iservice<hello> { public object execute(hello request) { return new helloresponse { result = "hello, " + request.name }; } }
here example of client code:
var response = client.send<helloresponse>(new hello { name = "world!" }); console.writeline(response.result); // => hello, world
you can find more complex examples , walk-throughs at: servicestack.hello
Comments
Post a Comment