I am using WCF for sending and getting data to and from 2 different win form applications running in the same machine. I am using namedpipe and duplexchannel. My client side implementation is shown below.
InstanceContext myContext = new InstanceContext(this);
NetNamedPipeBinding nb = new NetNamedPipeBinding();
nb.MaxBufferPoolSize = 5000000;
nb.MaxBufferSize = 500000;
nb.MaxReceivedMessageSize = 500000;
nb.ReceiveTimeout = TimeSpan.FromMinutes(5);
DuplexChannelFactory<IService> myProxy = new DuplexChannelFactory<IService>(myContext, nb, new EndPointAddress("net.pipe://localhost/MyService"));
IService myServiceClient = myProxy.CreateChannel();
And Server side implementation is shown below:
NetNamedPipeBinding np = new NetNamedPipeBinding();
np.MaxBufferPoolSize = 5000000;
np.MaxBufferSize = 500000;
np.MaxReceivedMessageSize = 500000;
host.AddServiceEndpoint(typeof(IService), np, "net.pipe://localhost/MyService");
host.OpenTimeout = TimeSpan.FromMinutes(5);
host.CloseTimeout = TimeSpan.FromMinutes(5);
host.Open();
I can pass about 100 object collection (ObservableCollection<Customer>) from 1 application through callback to other app. But if I make it 1000 or greater objects, the following Timeout Exception error occurs.
The write to the pipe did not complete
within the allotted timeout of
00:00:00. The time allotted to this
operation may have been a portion of a
longer timeout.
What is the fault in my code ? Please help me to overcome this issue.
Thanks in advance...
Looks like this question was also asked and answered here:
http://social.msdn.microsoft.com/Forums/eu/wcf/thread/38926593-8ea6-481d-8c43-072b73292f6a
Related
I am posting this because I was unable to find any place on Stack Overflow that addresses this issue for a .Net-Core project utilizing WCF by adding the service reference through Connected Services.
My issue was that I was facing client side timeouts because of long running operation requests.
So, how does one increase the timeout values for the wcf client objects since .Net-Core no longer uses the web config to store the configuration values for the WCF service references? (Please see my provided answer)
Under Connected Services in Solution Explorer, after adding a WCF service, a few files are generated for that service. You should see a folder with the name you gave the WCF service reference and under that a Getting Started, ConnectedService.json and a Reference.cs file.
To increase any of the client service object's timeout values, open Reference.cs and locate method: GetBindingForEndpoint
Inside this method you should see something like this:
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IYourService))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
//Here's where you can set the timeout values
result.SendTimeout = new System.TimeSpan(0, 5, 0);
result.ReceiveTimeout = new System.TimeSpan(0, 5, 0);
return result;
}
Just use result. and the timeout you want to increase like SendTimeout, ReceiveTimeout, etc. and set it to a new TimeSpan with the desired timeout value.
I hope this proves to be a useful post to someone.
Answer by Ryan Wilson will work but only until you will try to update service. Reference.cs will be overwritten.
In .NET Core 3.1 you can grammatically modify binding timeouts:
public MemoqTMServiceClass(string api_key)
{
client = new TMServiceClient();
var eab = new EndpointAddressBuilder(client.Endpoint.Address);
eab.Headers.Add(
AddressHeader.CreateAddressHeader("ApiKey", // Header Name
string.Empty, // Namespace
api_key)); // Header Value
client.Endpoint.Address = eab.ToEndpointAddress();
client.Endpoint.Binding.CloseTimeout = new TimeSpan(2, 0, 0);
client.Endpoint.Binding.OpenTimeout = new TimeSpan(2, 0, 0);
client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 10, 0);
}
Just implement the following partial method in the generated proxy class to configure the service endpoint. Place the partial method in your own file to make sure it will not be overwritten.
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
I am receiving a timeout from the Sharepoint Client Managed Object model.
Microsoft.SharePoint.Client.ServerException: The operation has timed out.
Basically, I am batching 100 updates and sending them at one go. It is no problem for me if takes time but I really want to avoid timeout exception.
I have tried in a million of ways to increase the timeout in the client context but they were all without success. I have used reflection to try to identity what the sharepoint is doing when calling the executequery method of the client context. sharepoint is basically creating an HttpWebRequest and sending it.
I have ended with the below code, but still without success:
public static void SetInfinteTimeout(this ClientContext ctx)
{
int timeout = 10 * 60 * 1000;
ctx.RequestTimeout = timeout;
ctx.PendingRequest.RequestExecutor.RequestKeepAlive = false;
ctx.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false;
ctx.PendingRequest.RequestExecutor.WebRequest.Timeout = timeout;
ctx.PendingRequest.RequestExecutor.WebRequest.ReadWriteTimeout = timeout;
System.Net.ServicePointManager.DefaultConnectionLimit = 200;
System.Net.ServicePointManager.MaxServicePointIdleTime = 2000;
System.Net.ServicePointManager.MaxServicePoints = 1000;
System.Net.ServicePointManager.SetTcpKeepAlive(false, 0, 0);
ServicePointManager.DnsRefreshTimeout = timeout; // 10 minutes
}
But I am still receiving a timeout error!
Is there anything else that I am missing please?
Any assistance would be greatly appreciated.
Have you tried
keeping default KeepAlive (true),
disabling Timeout and
keeping default MaxServicePointIdleTime value (which is 100 seconds by
default but you set to 2).
Just as:
public static void SetInfiniteTimeout(this ClientContext ctx)
{
ctx.RequestTimeout = -1; //ctx.RequestTimeout or System.Threading.Timeout.Infinite;
}
Also, how many seconds it takes for you to get timeout error, in your current configuration?
The solution was to use clientcallablesettings (SPWebApplication.ClientCallableSettings):
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.clientcallablesettings.aspx
This has an execution timeout property and other related settings.
In my case, I needed to add this in the Upgrade Actions as per the below code
using (SPSite site = new SPSite(siteURL))
using (SPWeb web = site.OpenWeb())
{
site.WebApplication.ClientCallableSettings.ExecutionTimeout = TimeSpan.FromMinutes(60);
site.WebApplication.ClientCallableSettings.MaxObjectPaths = 1000;
site.WebApplication.ClientCallableSettings.MaxResourcesPerRequest = 1000;
site.WebApplication.ClientCallableSettings.EnableStackTrace = true;
site.WebApplication.Update();
}
Hallo
I need a Tcp connection to a server alive in backgrond and applications will send data with this connection.I searched around and found WCF singleton is apporiate for this task
here is a code snippet that i use below
my question is that the good way and any problem can be with this?
string hostAddress = string.Empty;
try
{
srvHost = new ServiceHost(typeof(ControllerClass));
NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);
netTcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
netTcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
netTcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
srvHost.AddServiceEndpoint(typeof(IControllerContract), netTcpBinding, hostAddress);
srvHost.Credentials.WindowsAuthentication.AllowAnonymousLogons = true;
ServiceThrottlingBehavior serviceThrottlingBehavior = new ServiceThrottlingBehavior();
serviceThrottlingBehavior.MaxConcurrentCalls = 1000;
serviceThrottlingBehavior.MaxConcurrentInstances = 1000;
serviceThrottlingBehavior.MaxConcurrentSessions = 1000;
srvHost.Description.Behaviors.Add(serviceThrottlingBehavior);
srvHost.Open();
}
catch (System.TimeoutException timeoutEx)
{
Thread.Sleep(1000);
ReOpenHostConnection();//initialize again Controller Class
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("cannot start Service Ex:{0}", ex.ToString()), TraceEventType.Error.ToString());
}
//Controller Class Initialize Code Snippet
TcpClient iTcpClient = new TcpClient();
iTcpClient.Connect(serverIP, serverPort);
networkStream = iTcpClient.GetStream();
aSychDataByte = new byte[iTcpClient.ReceiveBufferSize];
networkStream.BeginRead(aSychDataByte, 0, incommTcpClient.ReceiveBufferSize, ReadAsych, null);
Why do you combine TcpClient with WCF? If you need low level Tcp communication build client and server based on low level Tcp classes. If you need service and you don't bother with message formats use WCF.
For your problem. You don't need singleton. You just need the connection to be opened. For this you need to create WCF proxy instance (open channel) on the client and call the service. It will create connection to service instance wich will live until you close the client proxy, until your service host stops working or until timeout (10 minutes of client inactivity by default).
I am trying to get working a WCF named pipe communication between two processes on the same computer (on XP), but I am having trouble with "large" messages disappearing. The messages that disappear contain a largish byte array and I have narrowed the failure down to when the array is around 16k in size. Smaller than that and the message gets through. Larger than that and the sender says it went fine but it is never received. I have tried bumping up the buffer sizes on both sender and receiver as per this code for the server:
PipeServer pipeServer = new PipeServer();
ServiceHost serviceHost = new ServiceHost(pipeServer, new Uri[] { new Uri(baseName) });
NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding();
netNamedPipeBinding.MaxBufferPoolSize = 5000000;
netNamedPipeBinding.MaxBufferSize = 500000;
netNamedPipeBinding.MaxReceivedMessageSize = 500000;
serviceHost.AddServiceEndpoint(typeof(ISSNPipeServer), netNamedPipeBinding, pipeName);
and this code for the client:
_callbacks = new PipeClientCallbacks();
NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding();
netNamedPipeBinding.MaxBufferPoolSize = 5000000;
netNamedPipeBinding.MaxBufferSize = 500000;
netNamedPipeBinding.MaxReceivedMessageSize = 500000;
_pipeFactory = new DuplexChannelFactory<ISSNPipeServer>(_callbacks,
netNamedPipeBinding,
new EndpointAddress(_targetPipe));
_pipeProxy = _pipeFactory.CreateChannel();
I am eventually looking to transfer arrays in the 60KB size, but this is my first serious WCF experience and I have no idea even where to really start looking.
You can enable WCF tracing on the server to get more information as to what the failure is. Likely, you still need to increase the reader quotas associated with the binding (NetNamedPipeBinding.ReaderQuotas). Check the MaxArrayLength one in particular.
I want to set the MaxReceivedMessageSize property to some higher limit (Due to (400) Bad Request error) in my client programmatically.
This is the code I am using...
WCFServiceTestClient wcfClient =
new WCFServiceTestClient(new wsHttpBinding(), strServiceURL);
My service url is dynamic and hence cannot use the web.config.
//The following code doesn't seem to take effect
((WSHttpBinding)wcfClient.ChannelFactory.Endpoint.Binding)
.MaxReceivedMessageSize = 2147483647;
What am I doing wrong?
Have you tried re-ordering the calls so that you set the MaxReceivedMessageSize before instantiating the client? eg,
var binding = new wsHttpBinding();
binding.MaxReceivedMessageSize = Int32.MaxValue;
var wcfClient = new WCFServiceTestClient(binding, strServiceURL);
This may or may not help your 400 error, though.
I had similar problems in my wcf-service and I solved it with:
CustomBinding binding = (CustomBinding)PDAServiceContractClient.CreateDefaultBinding();
HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
httpBindingElement.MaxBufferSize = Int32.MaxValue;
httpBindingElement.MaxReceivedMessageSize = Int32.MaxValue;
binding.Elements.Add(httpBindingElement);
string address = PDAServiceContractClient.EndpointAddress.Uri.ToString();
m_proxy = new PDAServiceContractClient(binding, new EndpointAddress(address));
This works well, though it's not that obvious. It retains all the existing binding properties and only adjusts the MaxReceivedMessageSize (which, incidentally, also increases MaxBufferSize to the same size).
Dim oClient as WcfClient = New WcfClient
CType(oClient.Endpoint.Binding, ServiceModel.BasicHttpBinding).MaxReceivedMessageSize = Int32.MaxValue