Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my WCF client timing out after calling a method in the WCF server that raises an event?
    primarykey
    data
    text
    <p>I have a WCF service hosted within a Windows service. There is s method in the WCF service that will raise an event that the Windows service subscribes to. When the event is raised and the Windows service catches it, the Windows service calls another WCF method to send a message to all connected clients. For some reason when I have all these these happen in this sequence an error is thrown:</p> <pre><code>This request operation sent to http://localhost:8731/Design_Time_Addresses/WCF/WCFService/ did not receive a reply within the configured timeout (00:00:29.9939996).... </code></pre> <p>Here is the relevant code from teh WCF service:</p> <pre><code>public event EventHandler&lt;CustomEventArgs&gt; CustomEvent; private static readonly List&lt;IMessageCallback&gt; subscribers = new List&lt;IMessageCallback&gt;(); public void SendMessageToClients(string msgType, string message) { subscribers.ForEach(delegate(IMessageCallback callback) { if (((ICommunicationObject)callback).State == CommunicationState.Opened) { callback.OnMessageReceived(msgType, message, DateTime.Now); } else { subscribers.Remove(callback); } }); } public bool messageHost() { try { if (CustomEvent != null) CustomEvent(null, new CustomEventArgs()); return true; } catch { return false; } } </code></pre> <p>And the Code from the Windows service:</p> <pre><code>wcfService = new WCF.WCFService(); sHost = new ServiceHost(wcfService); wcfService.CustomEvent += new EventHandler&lt;WCF.CustomEventArgs&gt;(wcfService_CustomEvent); sHost.Open(); private void wcfService_CustomEvent(object source, WCF.CustomEventArgs e) { wcfService.SendMessageToClients("log", "CLient connected!!"); osae.AddToLog("client message"); //just writes to a log file } </code></pre> <p>And the client just calls this:</p> <pre><code>wcfObj.messageHost(); </code></pre> <p>Here is the client config:</p> <pre><code> &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;wsDualHttpBinding&gt; &lt;binding name="WSDualHttpBinding_IWCFService" closeTimeout="00:00:10" openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:00:30" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"&gt; &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt; &lt;reliableSession ordered="true" inactivityTimeout="00:10:00" /&gt; &lt;security mode="Message"&gt; &lt;message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/wsDualHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWCFService" contract="WCFService.IWCFService" name="WSDualHttpBinding_IWCFService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;/client&gt; </code></pre> <p></p> <p>And the service config:</p> <pre><code>&lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="WCF.WCFService" behaviorConfiguration="WCFBehavior"&gt; &lt;endpoint address="" binding="wsDualHttpBinding" contract="WCF.IWCFService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange"/&gt; &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" /&gt; &lt;/baseAddresses&gt; &lt;/host&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="WCFBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; </code></pre> <p></p> <p>If I remove the SendMessageToClients call from the event in the Windows service it works and just logs the 'client message' as expected. Also, when the error is thrown about the timeout I can click continue and the the client continues to run and it received the message from the host. Why is the strange behavior happening?</p> <p><strong>EDIT:</strong> Marc led me to search in the right place: <a href="http://www.codeproject.com/KB/WCF/WCF_Duplex_UI_Threads.aspx" rel="nofollow">http://www.codeproject.com/KB/WCF/WCF_Duplex_UI_Threads.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload