Asynchronous WCF calls client timeout after 10 seconds

EDIT

After looking at this for a while, I thought it might be a configuration problem in my development area. However, after a clean download of the source code to another development machine, I still get this problem.

I have a Silverlight client that invokes WCF services asynchronously. With interruptions, I will get one of the common NotFound exceptions. Exceptions (which, as you know, are missing details) occur intermittently in almost all the services that I call.

Here is the thing. With a reasonable set of breakpoints, I was able to determine that the service side is doing fine. Data is retrieved and returned. The problem seems to be more on the client side.

Here rub ... I can sequentially make an exception if I make the service for more than 10 seconds. When I do this, it never returns to my completed callback. Instead, I get an exception in the client side of Reference.cs for the service:

  public System.Collections.ObjectModel.ObservableCollection<Project.Ui.SilverLight.ServiceName.ModelName> EndGetService(System.IAsyncResult result) { object[] _args = new object[0]; System.Collections.ObjectModel.ObservableCollection<roject.Ui.SilverLight.ServiceName.ModelName> _result = ((System.Collections.ObjectModel.ObservableCollection<roject.Ui.SilverLight.ServiceName.ModelName>)(base.EndInvoke("GetService", _args, result))); return _result; } 

The exception I get (not very useful):

 System.ServiceModel.CommunicationException was unhandled by user code Message=The remote server returned an error: NotFound. StackTrace: at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result) at Project.Ui.SilverLight.Service.ServicesClient.ServicesClientChannel.EndGetxxxxx(IAsyncResult result) at Project.Ui.SilverLight.Service.ServicesClient.Project.Ui.SilverLight.Service.IServices.EndGetxxxx(IAsyncResult result) at Project.Ui.SilverLight.Service.ServicesClient.OnEndGet(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) InnerException: System.Net.WebException Message=The remote server returned an error: NotFound. StackTrace: at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) InnerException: System.Net.WebException Message=The remote server returned an error: NotFound. StackTrace: at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState) InnerException: 

Binding information (names changed, but they correspond to the services being performed)

  <binding name="Project.WebUI.Services.xxxxxServices.customBinding0" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> <binaryMessageEncoding/> <httpTransport /> </binding> ... <service name="Project.WebUI.Services.xxxxxServices"> <endpoint address="" binding="customBinding" bindingConfiguration="Project.WebUI.Services.xxxxxServices.customBinding0" contract="Project.WebUI.Services.xxxxxServices" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> 

I believe that I checked the corresponding timeouts. The operationTimeout channel is set to at least one minute, as are ReceiveTimeout and OpenTimeout. Is there anything secret in Silverlight async WCF calls that need to be configured to tell him that it lasts more than ten seconds?

+6
exception silverlight wcf
source share
5 answers

The reason you are not receiving is NOT due to a timeout. I lost a week trying to figure it out.

I have links to silverlight, but this is not a Silverlight related issue.

An error not found exists due to the method of creating error codes. You need to catch any errors and change the error code - this will lead to the fact that errors will be reported properly and will not be disabled due to security.

If you think about it, the server was not found because the call is asynchronous and it died due to an exception in your code.

I use this class in my wcf service to connect - I do this through web.config, however it is not so difficult to change its wit ha class level attribute on the service itself.

you probably want to remove all materials from the contract. Its use in the project that I am working on, but is in no way related to this problem.

  [AttributeUsage(AttributeTargets.Class)] public class FaultBehavior : Attribute, IServiceBehavior, IEndpointBehavior { public class SilverlightFaultMessageInspector : IDispatchMessageInspector { public void BeforeSendReply(ref Message reply, object correlationState) { Contract.Assume(reply !=null ); if (reply.IsFault) { HttpResponseMessageProperty property = new HttpResponseMessageProperty(); // Here the response code is changed to 200. property.StatusCode = System.Net.HttpStatusCode.OK; Contract.Assume(reply.Properties != null); reply.Properties[HttpResponseMessageProperty.Name] = property; } } public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { // Do nothing to the incoming message. return null; } } #region IServiceBehavior Members void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) { } void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { Contract.Assume( serviceHostBase != null); Contract.Assume(serviceHostBase.ChannelDispatchers != null); foreach (ChannelDispatcher cDispatcher in serviceHostBase.ChannelDispatchers) { Contract.Assume(cDispatcher != null); Contract.Assume(cDispatcher.Endpoints != null ); foreach (EndpointDispatcher endpointDisbatcher in cDispatcher.Endpoints) { Contract.Assume(endpointDisbatcher != null); Contract.Assume(endpointDisbatcher.DispatchRuntime != null); Contract.Assume(endpointDisbatcher.DispatchRuntime.MessageInspectors != null); endpointDisbatcher.DispatchRuntime.MessageInspectors.Add(new SilverlightFaultMessageInspector()); } } } void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { } #endregion #region IEndpointBehavior Members void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { } void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { Contract.Assume(endpointDispatcher != null); Contract.Assume(endpointDispatcher.DispatchRuntime != null); Contract.Assume(endpointDispatcher.DispatchRuntime.MessageInspectors != null); SilverlightFaultMessageInspector inspector = new SilverlightFaultMessageInspector(); endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector); } void IEndpointBehavior.Validate(ServiceEndpoint endpoint) { } #endregion } 

you need to determine the element that will be displayed in the web.config liek this file

 public class FaultHandlerElement : BehaviorExtensionElement { protected override object CreateBehavior() { return new FaultBehavior(); } public override Type BehaviorType { get { return typeof(FaultBehavior); } } } 

and then in the web configuration you need to add this to the service model section - the failure exception will have a wavy line below it;)

 <system.serviceModel> <extensions> <behaviorExtensions> <add name="faultBehaviourExtension" type="CopSilverlight.Web.FaultHandlerElement, CopSilverlight.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions 

you then bind your behavior before use this way

  <serviceBehaviors> <behavior name="basicHttpBehaviour"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <faultBehaviourExtension /> </behavior> 

An alternative โ€œfixโ€ is to enable tracing in your wcf services. It should be noted that if you do not create a directory, it simply wonโ€™t create a log

  <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> <listeners> <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\appName\wcf.svclog" /> </listeners> </source> </sources> </system.diagnostics> 

the recording is not perfect, although the first solution really fixes the problem.

I implemented both of them, and now I get exceptions bubbling up to my silverlight application, as you would expect.

+4
source share

It could be something online.

In this, they received the same error message, but it was really the timeout of gateway 504.

If, for example, you have a proxy server between the silverlight application and the server that closes the connection so that the callback cannot reach the client.

+3
source share

I wonder if it's like this

Theft from this answer:

Check the registry on HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings for a value called ReceiveTimeout and delete if it is there. - cdm9002 May 4 at 2:30 pm

Or, reset is the default value, which is 1 hour (3,600,000 milliseconds).

+3
source share

In the above configuration files, it looks like they are from the server configuration. Have you also checked client-side configuration? The SendTimeout and ReceiveTimeout properties on the client channel are equal to one minute by default, but perhaps they could be configured or redefined. And, of course, you should check both XML configuration files, but also where you create the binding in the code, since you can set properties there that conflict with your configuration files. (Both on the client and on the server.)

+1
source share

Just out of curiosity, what is idleTimeout in web.config currently installed? Is it possible to set 10 minutes?

UPDATE

So here is your problem! This is a known issue with idleTimeout! Just remove this setting and everything should work again.

0
source share

All Articles