c# - WCF Self host Publish/Subscribe. How to call publish method from host? -


hello have publish/subscribe wcf service hosted in application rather iis.

here service interfaces

[servicecontract(callbackcontract = typeof(imonitorpublishing))] public interface imonitorsubscribing {     [operationcontract]     void subscribe(int processid);      [operationcontract]     void unscubscribe(int processid);      [operationcontract]     void publishwriteconsole(string name); }   [servicecontract] public interface imonitorpublishing {     [operationcontract(isoneway = true)]     void writeconsole(string line); } 

here subcription service

public class monitorsubscriptionservice : imonitorsubscribing {     public delegate void writeconsoleeventhandler(object sender,    serviceeventargs e);     public static event writeconsoleeventhandler writeconsoleevent;      imonitorpublishing publishcallback = null;     writeconsoleeventhandler writeconsolehandler = null;      public void subscribe(int processid)     {         publishcallback = operationcontext.current.getcallbackchannel<imonitorpublishing>();         writeconsolehandler = new writeconsoleeventhandler(publishwriteconsolehandler);         writeconsoleevent += writeconsolehandler;         //publishwriteconsole("winning")     }      public void unscubscribe(int processid)     {         writeconsoleevent -= writeconsolehandler;     }      public void publishwriteconsole(string text)     {         serviceeventargs se = new serviceeventargs();         se.text = text;         writeconsoleevent(this, se);     }      public void publishwriteconsolehandler(object sernder, serviceeventargs se)     {         publishcallback.writeconsole(se.text);     } } 

the services host fine , able add service reference in client application. if uncomment "winning" line triggers client's callback method fine (after time). leads me believe subscription , callbacks working great.

my question is, @ various points in host application wish print subscribed clients console via publishwriteconsole callback method. how make function call in host application need connect service own application hosting? i'm alot confused appreciated.

here relevant app.config bits

<services>   <service behaviorconfiguration="monitor.monitorsubscriptionservicebehaviour"            name="monitor.monitorsubscriptionservice">     <host>       <baseaddresses>         <add baseaddress="net.tcp://localhost:5050/monitor"/>       </baseaddresses>     </host>     <endpoint address=""  binding="nettcpbinding" bindingconfiguration="" contract="monitor.imonitorsubscribing">       <identity>         <dns value="localhost"/>       </identity>     </endpoint>     <endpoint address="mex" binding="mextcpbinding" contract="imetadataexchange"/>   </service> </services> <behaviors>   <servicebehaviors>     <behavior name="monitor.monitorsubscriptionservicebehaviour">       <servicemetadata httpgetenabled="false"/>             <servicedebug includeexceptiondetailinfaults="false" />     </behavior>   </servicebehaviors> </behaviors> 


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -