System.TimeoutException in WCF service C# - c#

I have a problem with my WCF service. I'm getting thw following exception after the program runs three hours perfectly.
System.TimeoutException: The request channel timed out while waiting for a reply after 00:00:59.9843998. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout
I do not think that increasing the timeout would be a solution. I think the just would throw the exception a couple of minutes later. Maybe I have to change any settings on my listener server. Could it be that my machine close the port after a certain period of time?
I call my service like that:
IServices service = null;
service = ChannelFactory<IServices>.CreateChannel(
new BasicHttpBinding(),
new EndpointAddress(
port));
result = service.addAppointments(appList);
My listener:
ServiceHost host = new ServiceHost(service);
host.AddServiceEndpoint(typeof(
IServices),
new BasicHttpBinding(), port);
host.Open();
Thats all. No further settings were required up to now.

You can add through config the tracer for WCF. This will help you to find out where the problem is.
http://msdn.microsoft.com/en-us/library/ms733025.aspx
http://msdn.microsoft.com/en-us/library/ms732023.aspx

Related

WCF client unable to establish secure connection during machine boot

In our setup we have a WCF client in a windows service that needs to request configuration from a central server hosting a WCF endpoint. Client/Server communication works like a charm when the client machine is fully up and running but fails during boot.
below is the Exception throw:
EXCEPTION THROWN: System.TimeoutException: Client is unable to finish
the security negotiation within the configured timeout
(00:00:19.9839990). The current negotiation leg is 1
(00:00:19.8689925).---> System.TimeoutException: The request channel
timed out attempting to send after 00:00:19.8689925. Increase the
timeout value passed to the call to Request or increase the
SendTimeout value on the Binding. The time allotted to this operation
may have been a portion of a longer timeout
The channel connection is secured with var binding = new WSHttpBinding("SecureWsHttpBinding") and Certificates.
I have tried with various increasing OperationTimeout values from 60s to 120s with basically the same result.
At the time when the Exception occur the network card is up and running.
Do anybody know why this is happening under these conditions? Do SecureWsHttpBinding require some windows services to run?

Disposing faulted service channels on client side in WCF

I have a WCF Websocket client server communication. What I want to do on client side, is to keep trying to reconnect to the server, if server was shut down or something. From what I know, once a server is shut down, channel is in faulted state so I cannot use it again. I need to create a new one, but I am afraid, that there is memory leak in my solution:
creating the websocket service:
InstanceContext context = new InstanceContext(this);
ServiceReference.SomeServiceClient client = new ServiceReference.MLogDbServiceClient(context);
reconnecting:
client.Abort();
client = new ServiceReference.MLogDbServiceClient(context);
In Windows Task Manager I saw that in two minutes my app grew from 29mb to 48mb while I was keeping to create new channel every 20ms ( it was just for memory leak test purposes ). Anyone has a leak-free solution for me?
My client application NEEDS to keep reconnecting to the server (not so frequently but still). Greetings

WCF connection timeout when trying to connect to an unreachable host

I set connection timeout the following way:
var binding = new NetTcpBinding(SecurityMode.None, true);
binding.OpenTimeout = TimeSpan.FromSeconds(5);
Then I try to connect to the service like this:
var client = new ServiceClient(new InstanceContext(eventClient), binding, address);
client.Subscribe();
Whenever the client attempts to connect to a reachable host but without the service running it will timeout in 5 seconds like I expect it to. When the client attempts to connect to an unreachable host it freezes for 15-20 seconds or so.
Is there any way to make it timeout faster?

TChannel state change events?

hopefully a simple WCF beginners question..
I have a WCF channel factory, returning a service proxy TChannel:
// setup connection to server
var endpointAddress = new EndpointAddress(GetAppSetting("Endpoint"));
var tcpBinding = new NetTcpBinding();
channelFactory = new DuplexChannelFactory<IExcelServer>(this, tcpBinding, endpointAddress);
server = channelFactory.CreateChannel();
I would like to know when this service proxy changes state (Faulted, Closed etc). I can see events on the ChannelFactory itself, however I'm not sure this is the same as the channel itself, and even here stopping the server process doesn't cause a state transition.
This is a CallbackContract service, and in almost all interactions the server is sending data to the client. Therefore I can't simply rely on catching the failure when I make a server call from the client.
Should I send a heartbeat from client to server to trigger the state change?
The instance you get back from CreateChannel implements TChannel but also IClientChannel which has state changed events like Closed, Closing, Opened, etc.:
server = channelFactory.CreateChannel();
((IClientChannel)server).Faulted += FaultedHandler;
P.S: As you pointed out, the states of the channel and channel factory are related but not the same. If a Channel is faulted it doesn't necessarily mean that the ChannelFactory is.

What are named pipes (net.pipe) limitations?

I have a program that run in a loop, each iteration runs in a different thread and I'm creating new process that open new service host:
ServiceHost _host = new ServiceHost(_service, new Uri("net.pipe://localhost/" + i_PipeName));
_host.AddServiceEndpoint(typeof(ICommandService), new NetNamedPipeBinding() { TransferMode = TransferMode.Buffered }, i_PipeName);
_host.Open();
from my main program I connect to the open .net pipe at the following way:
ICommandService ServiceProxy = ChannelFactory<ICommandService>.CreateChannel
(new NetNamedPipeBinding(), new EndpointAddress(#"net.pipe://localhost/" + i_PipeName" + #"/" + i_PipeName));
So my problem is that for the first 200+ proccess/iterations it working fine, I can open connection and pass messages but later on there errors that starts to appear:
There was no endpoint listening at
net.pipe://localhost/pipea0360/pipea0360 that could accept the
message. This is often caused by an incorrect address or SOAP action.
See InnerException if present, for more details.
My question is if there are any limitations on the number of pipes I can open in parallel?
Is this because I open so many proccesses?
Have you ruled out a race condition, where the client is attempting to connect to a pipe that the server hasn't established yet? If you have a lot of active threads on the server, it could easily delay the thread that is supposed to start listening. That could explain why it works in the beginning.
In general, having a server thread for each client doesn't scale well; you'll get better performance with a thread pool approach.

Categories