c# - WCF Callback not calling back -
i have read many articles here on so, , on msdn , code project. , still answer eludes me.
i have created wcf service has callback contract, , windows forms app (test harness) implements callback interface.
here interfaces:
[servicecontract] public interface icacheservice { [operationcontract] bool addtocache(string type, string key, string source, object item, int duration); [operationcontract] bool remove(string key); } [servicecontract(sessionmode=sessionmode.required, callbackcontract=typeof(isearchcallback))] public interface icachesearch { [operationcontract(isoneway=true)] void searchcache(string source); } public interface isearchcallback { [operationcontract(isoneway=true)] void oncallback(object data); } my service (left out add , remove conserve space - work expected):
[servicebehavior(instancecontextmode = instancecontextmode.single, concurrencymode=concurrencymode.multiple)] public class cachingservice : icacheservice, icachesearch, idisposable { private list<icache> _cachelist = new list<icache>(); private isearchcallback _callback = null; public void searchcache(string source) { try { _callback = operationcontext.current.getcallbackchannel<isearchcallback>(); list<object> items = new list<object>(); foreach (icache cache in this._cachelist) { foreach (cacheitem item in cache.getcacheitemsbysource(source)) { items.add(item.value); } } readonlycollection<object> outlist = new readonlycollection<object>(items); _callback.oncallback(outlist); } catch { } } } my service hosted in windows service. here system.servicemodel section app.config:
<system.servicemodel> <bindings> <wshttpbinding> <binding name="wshttpbinding_icacheservice" closetimeout="00:01:00" opentimeout="00:01:00" receivetimeout="00:01:00" sendtimeout="00:01:00" maxbufferpoolsize="2147483647" maxreceivedmessagesize="2147483647"> <readerquotas maxarraylength="2147483647" maxbytesperread="2147483647" maxdepth="2147483647" maxnametablecharcount="2147483647" maxstringcontentlength="2147483647"/> </binding> </wshttpbinding> <wsdualhttpbinding> <binding name="wsdualhttpbinding_icachesearch" closetimeout="00:01:00" opentimeout="00:01:00" receivetimeout="00:01:00" sendtimeout="00:01:00" maxbufferpoolsize="2147483647" maxreceivedmessagesize="2147483647" clientbaseaddress="http://localhost:5057/wsdualhttpbinding" usedefaultwebproxy="true" transactionflow="false"> <readerquotas maxarraylength="2147483647" maxbytesperread="2147483647" maxdepth="2147483647" maxnametablecharcount="2147483647" maxstringcontentlength="2147483647"/> </binding> </wsdualhttpbinding> </bindings> <behaviors> <servicebehaviors> <behavior> <servicemetadata httpgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="false"/> </behavior> </servicebehaviors> </behaviors> <services> <service name="cacheservice.cachingservice"> <host> <baseaddresses> <add baseaddress="http://localhost:5055/cachingservice/"/> </baseaddresses> </host> <endpoint address="search" binding="wsdualhttpbinding" contract="cacheservice.icachesearch" /> <endpoint address="" binding="wshttpbinding" contract="cacheservice.icacheservice" /> <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange" /> </service> </services> <client> <endpoint address="http://localhost:5055/cachingservice/search" binding="wsdualhttpbinding" bindingconfiguration="wsdualhttpbinding_icachesearch" contract="cacheservice.icachesearch" name="wsdualhttpbinding_icachesearch" /> <endpoint address="http://localhost:5055/cachingservice" binding="wshttpbinding" bindingconfiguration="wshttpbinding_icacheservice" contract="cacheservice.icacheservice" name="wshttpbinding_icacheservice" /> </client> </system.servicemodel> finally, created simple windows forms app test. declared as:
[callbackbehavior(usesynchronizationcontext = false, concurrencymode = concurrencymode.single)] public partial class form1 : form, cacheservice.icachesearchcallback { instancecontext context = null; cacheservice.cacheserviceclient _service = null; cacheservice.cachesearchclient _proxy = null; private void form1_load(object sender, eventargs e) { _synccontext = system.threading.synchronizationcontext.current; _service = new cacheservice.cacheserviceclient(); this.datagridview1.autogeneratecolumns = true; context = new instancecontext(this); _proxy = new cacheservice.cachesearchclient(context); refreshlist(); } private void refreshlist() { _proxy.searchcache("mysource"); } public void oncallback(object data) { this._data = data; this.datagridview1.datasource = this._data; } the call service (_proxy.searchcache("mysource")) executes method on service , service calls _callback.oncallback(outlist). callback method implemented in test app never called , data never conveyed test app.
again, have looked @ every recent wcf article on , many other blogs , code sites. feel need pair of eyes point out obvious can work.
many thanks,
robert
Comments
Post a Comment