We recently switched out codebase to programmatically set WCF bindings and generate proxies. We've moved away from defining the configuration in the ServiceReferences.clientconfig. Since then, some long WCF calls have been timing out in Silverlight and I have no idea why. I've set all the timeouts in the bindings to 24 hours. I need some suggestions on how to diagnose the problem.
At first I thought that the problem was a timeout on the client side because the error happens after a couple of minutes, but the code on the server side continues, and eventually completes successfully. But I'm not completely sure of this now. I was watching the Kestrel log window, and noticed that it said that the request finished at the same time that the error popped up in Silverlight, even though the operation was continuing on the server side. But, I can't find any information on setting the OperationTimeout on the server side. Here is the binding on the server side:
private static CustomBinding CreateCustomBinding()
{
var httpTransportBindingElement = new HttpTransportBindingElement
{
MaxBufferPoolSize = 2147483647,
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
var bindingElements = new BindingElementCollection();
var binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement
{
MaxReadPoolSize = 2147483647,
MaxSessionSize = 2147483647,
MaxWritePoolSize = 2147483647,
ReaderQuotas = new XmlDictionaryReaderQuotas
{
MaxDepth = 2147483647,
MaxStringContentLength = 2147483647,
MaxArrayLength = 2147483647,
MaxBytesPerRead = 2147483647,
MaxNameTableCharCount = 2147483647
}
};
bindingElements.Add(binaryMessageEncodingBindingElement);
bindingElements.Add(httpTransportBindingElement);
var binding = new CustomBinding(bindingElements)
{
Name = "UserNameBinding",
CloseTimeout = new TimeSpan(24, 0, 0),
OpenTimeout = new TimeSpan(24, 0, 0),
ReceiveTimeout = new TimeSpan(24, 0, 0),
SendTimeout = new TimeSpan(24, 0, 0)
};
return binding;
}
Here is the code for how the binding is created on the client side. Let me know if there is any other code that is relevant here that I am missing. I have debugged this code to ensure that the proxy is getting this binding set on it.
public static Binding GetWCFBinding(bool isHttps)
{
var binding = new CustomBinding
{
CloseTimeout = new TimeSpan(24, 00, 00),
OpenTimeout = new TimeSpan(24, 00, 00),
ReceiveTimeout = new TimeSpan(24, 00, 00),
SendTimeout = new TimeSpan(24, 00, 00)
};
var binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement();
binding.Elements.Add(binaryMessageEncodingBindingElement);
binding.Elements.Add(isHttps
? new HttpsTransportBindingElement()
{
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
TransferMode = TransferMode.Buffered
}
: new HttpTransportBindingElement()
{
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
TransferMode = TransferMode.Buffered
});
return binding;
}
I've also put this line in the constructor of the proxy:
InnerChannel.OperationTimeout = new TimeSpan(24, 0, 0);
The error is this non-descript error that always returns when something goes wrong on the server or the client times out:
Module: Adapt.Presentation.Xivic.CodeGeneration Exception Message: The remote server returned an error: NotFound. Time: 6/03/2017 4:17:55 PM Stack Trace: ThrowForNonSuccess at offset 90 in file:line:column :0:0 HandleNonSuccess at offset 87 in file:line:column :0:0 GetResult at offset 30 in file:line:column :0:0 MoveNext at offset 525 in file:line:column :0:0 Full Exception: System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.b__9(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.b__0(Object sendState) --- End of inner exception stack trace --- 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) --- End of inner exception stack trace --- at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Adapt.Presentation.Xivic.CodeGeneration.d__15.MoveNext()