Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 Windows Services. Each Windows Service is hosting a WCF Service.

ControllerService hosts ControllerWCF
CalcService hosts CalcWCF

There are few methods in ControllerWCF that will go towards CalcWCF to process some data. Then I have a third console application to test my services.

Using the third console application, to test it out I created 3 connections.
1st goes directly to the ControllerWCF which executes a method in ControllerWCF
2nd goes directly to the CalcWCF which executes a method in CalcWCF
3rd goes directly to the ControllerWCF which will execute a method in CalcWCF (same method as the 2nd connection)

When running the application, the 1st and 2nd connection will execute flawlessly. When going to the 3rd connection it will crash and return this exception message:


An existing connection was forcibly closed by the remote host

System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()
System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)
System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)


Also got this message error in the Service Trace Viewer
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '10675199.02:48:05.4775807'.


-		$exception	{"The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:57.2419783'."}	System.ServiceModel.CommunicationException


SocketException: An existing connection was forcibly closed by the remote host


The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9989991'.

What I have tried:

I've activated the service trace, I've increased the timeouts, maxItemsInObjectGraph, etc etc.

I still don't know how to solve this problem. I will paste my app.config from all WCF Services soon.
Posted
Updated 21-Jun-17 1:09am
v5
Comments
F-ES Sitecore 20-Jun-17 11:16am    
Check the config in ControllerWCF has the right details for the CalcWCF service, ie the right uri\host\port etc. Maybe add some logging to ControllerWCF to log exactly what uris it is about to call.
GuilhermeCoollink 20-Jun-17 11:19am    
When the CalcService starts and hosts the CalcWCF, the Uri of CalcWCF is being stored in the database. ControllerWCF uses ControllerService to fetch the Uri for CalcWCF. I started printing stuff to the Console to make sure it's fetching the correct Uri and everything is smooth there :/
F-ES Sitecore 20-Jun-17 11:22am    
Try a Fiddler trace so see if that can give you any more info.
GuilhermeCoollink 20-Jun-17 11:26am    
Will try the Fiddler trace. This screen shows the output coming from both services plus the testing console http://imgur.com/ll97JBe
GuilhermeCoollink 20-Jun-17 11:40am    
Just noticed it doesn't work with net.tcp only with http. Fiddler is no good then :x

Ok I found the problem... I was using a custom ChannelWrapper that was already built from the previously developer and I changed the way to communicate using the "traditional" ChannelFactory from MSDN


using (ChannelFactory<IWCFCommonService> channelFactory2 = new ChannelFactory<IWCFCommonService>(new NetTcpBinding()))
                {
                    IWCFCommonService channel2 = channelFactory2.CreateChannel(new EndpointAddress("net.tcp://127.0.0.1:8991/CLCalcWCF/Service"));
                    channel2.CallTestCalc();
                }


This allowed me to work without any problems. Nevermind this issue... was "legacy" code problem <.<
 
Share this answer
 
If it only takes to long and perhaps your 60 second default isn't enough. Try to open the transmission time:
Configuring Timeout Values on a Binding | Microsoft Docs[^]

If the problem isn't timeout but an error, make sure you catch all errors in your method on the service and return errors if you will wrappend in FaultException

How to: Wrap Managed Exceptions in a FaultException[^]

You don't want to risk your communication channel dying by unhandled exceptions, as you won't notice until your next call.
 
Share this answer
 
The most important thing to check with such an error message is whether it's really a timeout problem: you'll receive that misleading message even when the error happens immediately.

A typical cause of problems are types which are not known to the WCF service (or have different versions on the different machines).

Also look at the sizes of objects/string/arrays which can be transmitted between services.

As an easy step for analysis, I'd replace the problematic call between the services with a simple method using common types. I sometimes integrate a method string Foo() for such purposes in my services: if that works, the basic WCF configuration, firewall and such things are OK.
 
Share this answer
 
Comments
GuilhermeCoollink 21-Jun-17 6:48am    
I just created a demo application to try it out, this is what I came up with:

https://github.com/GuilhermeGomesCL/WCF_Calling_WCF/tree/master/WCF_Calling_WCF

Here, this works fine. I can call the WCF from another WCF. I'm implementing exactly the same way on my other application... but still gives me an error and I've created a simple method that returns nothing. All of them are void and still I get the same socket error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900