質問

Maybe I am implementing WCF improperly, but I seem to be getting a WCF exception while using NetNamedPipedBindings after making numerous calls.

Here is the high level of what I am doing. Basically, I am working on an out of proc exe and using WCF named pipes to communicate back and forth. I leave my host open via this attribute:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
    ConcurrencyMode = ConcurrencyMode.Multiple)]

Then, in my client I create a static DuplexChannelFactory that I instantiate once and then use as needed via:

channelFactory.CreateChannel().MakeCall();

I have added a Ping method just to make sure that the host is working properly (since the host will send events back that we do not want to miss without knowing). This Ping method runs once every 5 seconds and simply returns a true. However, after running for a couple of minutes I get a TimeoutException. Here is my exception trace:

Server stack trace: at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

I have opened JustDecompile and see that this error is most likely happening here:

connection = this.connectionPoolHelper.EstablishConnection(timeout)

However, I do not see any reason why this would timeout after working for a couple of pings previously? What setting do I need to set to make this infinite and/or is there another way for me to implement this WCF event server (it is used for on-demand processing too) from the client or server side?

UPDATE

I make about 6 pings before I start to see the call attempt and no return.

役に立ちましたか?

解決

The problem was that you cannot call CreateChannel over and over it appears. There is no dispose method as this is just a proxy of my WCF interface. So, I just solved this by storing the reference to the proxy and recreating it if the host needed re-instantiated.

You would think there would be some sort of documentation about this. It especially does not help when there are blogs that are written where they do call CreateChannel multiple times.

UPDATE:

Here is what I found as to how this should be solved...although it did not work for me.., but seems to for others

Snipped code in case the link dies:

You have to use a using that casts to IClientChannel, and then reset your reference inside the using. The channel will close properly, but your reference will remain open. Notice the casts

using (IClientChannel client = (IClientChannel)channelFactory.CreateChannel())
{
    var proxy = (IMyInterface)client;
}

他のヒント

You should use PipeList from sysinternals to see if you keep creating new pipes unnecessarily. They will show up as GUIDs. See MSDN blogs for further reference on WCF named pipe naming conventions.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top