vb.net - Windows Service and WPF Application Side by Side -
i developing application using wpf (vb.net) ,the application listens event (this working fine) ,the event returns variable passed web service when web service response arrives , dialog window appears showing values response these questions : how run listening part of code windows service ? cant service part initiate gui display response web service ?
the service communicate application run user. services can't show ui components. way did this: 1. have service application running listens event. 2. service application implements interface defines methods , properties i'm going utilize communicate ui application.
public interface imyservice { string mystring { get; } string mymethod(); }
the service implements interface , marshalbyrefobject:
public class myservice : marshalbyrefobject, imyservice {/*...*/}
when service starts, register channel communication calling these 2 methods in constructor of service:
private static void registerchannel() { seek { tcpserverchannel channel = new tcpserverchannel(mynamespace.api.myservicechannels.myservicechannel); channelservices.registerchannel(channel, false); } grab { } //to suppress exception when channel registered } private static void registerremotableclass() { seek { remotingconfiguration.registerwellknownservicetype(typeof(myservice), "myservice", wellknownobjectmode.singleton); } grab { } }
in gui application, seek connect service:
public void getservice() { seek { string tcpaddress = myservicechannels.myapptcpaddress; channelservices.registerchannel(new tcpclientchannel(), false); _serviceapp = (imyservice)activator.getobject(typeof(imyservice), tcpaddress); } grab (exception ex) { //... } }
if went well, can access properties, methods , events of service application.
wpf vb.net windows
No comments:
Post a Comment