Tuesday 22 March 2011

WCF service giving socket connection time-out error

After spending about 3 hrs on this I came to know that I was doing a silly mistake. Here is the full scenerio...


I've created a class named ChangeSet inheriting from the interface IChangeSet. I wrapped up the result in a wrapper called GetAllLaunchEntitysResponse and returning from the proxy class as follows:


        public GetAllLaunchEntitysResponse GetAllChangeSetList()
        {
            using (var factory = new TriboldChannelFactory<IChangeSetService>("IChangeSetService"))
            {
                return factory.CreateChannel().GetAllChangeSet();
            }
        }


Also, before doing that, I've already created a WCF service and proxy to call the service endpoint. The function GetAllChangeSet() returns a list of change set interface (List<IChangeSet>) wrapped in GetAllLaunchEntitysResponse object from the DAL. 


I was getting the following error from the WCF service when calling from a proxy service.


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:01:00'.

First thing that came in my mind is to check the configuration files. The endpoint was already set in the config file for both client & server as well. The timeout setting was set for 5 minutes...so that was not the case of time-out but something else which was triggering this error to raise.


Then I start thinking if there might exists any complex data-types present in ChangeSet class causing problem in serialization. So I commented complex data types and keep Int & string data-types only and call the service. Result was the same as before.


Then I change the return type from List<IChangeSet> to IChangeSet thinking there might be some problem returning list from WCF service. I call  the service & again result was same as before.


Now the last thing I tried was to replace the class name instead of interface from the list. i.e. List<IChangeSet> replaced by <List<ChangeSet> and call the WCF service again.


HURRAH....This time it worked....The silly mistake I was doing was returning a list of interfaces of ChangeSet (List<IChangeSet>) which cannot be seriablized since only class, struct and enum can be serialized and not interface [the fundamental concept of WCF service]


I am writing this post for someone who is doing the same mistake as I did. Be sure to serialize only class object and not Interface.

Test Blog

This is test blog