Wednesday, 15 January 2014

c# - WCF Duplex Service Channel Close -



c# - WCF Duplex Service Channel Close -

i have application based around wcf duplex service. have problems when user "restarts" work application does... under hood, client side closes connection wcf service , creates another. service contract defined so...

[servicecontract(namespace="net.tcp://namespace.myservice", sessionmode=sessionmode.required, callbackcontract=typeof(iservicecallback))] public interface imyservice { [operationcontract(isoneway=true)] void dowork(); } public interface iservicecallback { [operationcontract(isoneway=true)] void sendmessage(string message); }

the implementation defined as:

[servicebehavior(concurrencymode = concurrencymode.single, instancecontextmode = instancecontextmode.persession, usesynchronizationcontext = false, includeexceptiondetailinfaults = true)] public class myservice : imyservice { public void dowork() { var callback = operationcontext.current.getcallbackchannel<iservicecallback>(); callback.sendmessage("hello, world."); } }

the configuration client follows:

<system.servicemodel> <bindings> <nettcpbinding> <binding name="net.tcp" receivetimeout="02:00:00" sendtimeout="02:00:00" maxreceivedmessagesize="2147483647"> <security mode="none"/> </binding> </nettcpbinding> </bindings> <client> <endpoint address="net.tcp://localhost:8000/myservice/myservice" binding="nettcpbinding" bindingconfiguration="net.tcp" contract="externalservicereference.imyservice"> </endpoint> </client> </system.servicemodel>

config service:

<system.servicemodel> <behaviors> <servicebehaviors> <behavior name="servicebehaviour"> <servicemetadata /> </behavior> </servicebehaviors> </behaviors> <bindings> <nettcpbinding> <binding name="nettcp" sendtimeout="01:00:00" receivetimeout="01:00:00" > <security mode="none"> </security> </binding> </nettcpbinding> </bindings> <services> <service behaviorconfiguration="servicebehaviour" name="myservice.myservice"> <endpoint address="myservice" binding="nettcpbinding" bindingconfiguration="nettcp" name="net.tcp" contract="myservice.imyservice" /> <endpoint binding="mextcpbinding" bindingconfiguration="" name="net.tcp" contract="imetadataexchange" /> <host> <baseaddresses> <add baseaddress="net.tcp://localhost:8000/myservice" /> </baseaddresses> </host> </service> </services>

in client's contructor:

var callback = new callbackimplementation(); _context = new instancecontext(callback); _proxy = new myserviceproxy(_context);

i'm trying next before found new connection:

seek { if (_context != null) { _context.releaseserviceinstance(); _context.close(); } } grab (exception ex) { debug.writeline(ex.message); if (_context != null) { _context.abort(); } }

the issue see _context.close() phone call times out , throws exception. although i'm aborting channel, feels wrong me, , believe it's cause of freezing in application. know why close() phone call fails?

edit: missed before regarding callback implementation might relevant. looks this:

[callbackbehavior(concurrencymode = concurrencymode.single, usesynchronizationcontext = false, includeexceptiondetailinfaults = true)] public class callbackimplementation : iservicecallback { public void sendmessage(string message) { // message } }

the exception message "the servicehost close operation timed out after 00:00:30. because client failed close sessionful channel within required time. time allotted operation may have been portion of longer timeout.". there's no inner exception.

thanks

i don't see issue right off, find running traces on both client , server , examining results points me solution. set in .config files (client , server), create sure path points folder exists. run app, failure, shut downwards , run svctraceviewer.exe read results.

<system.diagnostics> <sources> <source name="system.servicemodel" switchvalue="information,activitytracing" propagateactivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="system.servicemodel.messagelogging"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedlisteners> <add initializedata="c:\logs\tracingandlogging-service.svclog" type="system.diagnostics.xmlwritertracelistener" name="xml" /> </sharedlisteners> <trace autoflush="true" /> </system.diagnostics>

c# wcf

No comments:

Post a Comment