The underlying connection was closed: An unexpected error occurred on a receive.

1,166 views
Skip to first unread message

John Carruthers

unread,
Apr 22, 2011, 9:19:56 PM4/22/11
to servic...@googlegroups.com
I get the following exception when trying to make a request to servicestack/xml/syncreply using the XmlServiceClient:

The underlying connection was closed: An unexpected error occurred on a receive.

Anybody experienced this or know how to fix it? I've tried using json and jsv and get the same error.

Using an old Silverstack.dll I found from September last year Silverlight can communicate with the webservice correctly.
Any ideas?

Demis Bellot

unread,
Apr 22, 2011, 10:21:05 PM4/22/11
to servic...@googlegroups.com
Hi John,

Unfortunately this is an unknown error so will need a StackTrace and potentially DTO's used in order to investigate this further.

The Service Clients have recently been enhanced but unfortunately the MonoTouch / Silverlight Service Clients haven't caught up with these changes yet. We are currently looking into better support these clients in this release.

Cheers,
Demis

John Carruthers

unread,
Apr 22, 2011, 10:34:59 PM4/22/11
to servic...@googlegroups.com
The full exception from the client is pasted below.
It looks like the server is closing the socket after making the request.
Is it possible to setup logging on the server side to see what the problem could be?

System.Net.WebException was unhandled
  Message=The underlying connection was closed: An unexpected error occurred on a receive.
  Source=ServiceStack.Common
  StackTrace:
       at ServiceStack.ServiceClient.Web.ServiceClientBase.HandleResponseException[TResponse](Exception ex, String requestUri) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceClient.Web\ServiceClientBase.cs:line 174
       at ServiceStack.ServiceClient.Web.ServiceClientBase.HandleResponseException[TResponse](Exception ex, String httpMethod, String requestUri, Object request) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceClient.Web\ServiceClientBase.cs:line 128
       at ServiceStack.ServiceClient.Web.ServiceClientBase.Send[TResponse](Object request) in C:\src\ServiceStack\src\ServiceStack.Common\ServiceClient.Web\ServiceClientBase.cs:line 106
       at ChessTouch.Core.Service.Service.DoRequest[TResponse](Object request) in C:\Users\KnyghtMare\Documents\Visual Studio 2010\Projects\ChessTouch.git\Core\Service\Service.cs:line 56
       at ChessTouch.Core.Service.Signon.DoSignon() in C:\Users\KnyghtMare\Documents\Visual Studio 2010\Projects\ChessTouch.git\Core\Service\Signon.cs:line 21
       at ChessTouch.Core.MultiplayerGame.<>c__DisplayClass2.<Connect>b__1() in C:\Users\KnyghtMare\Documents\Visual Studio 2010\Projects\ChessTouch.git\Core\MultiplayerGame.cs:line 37
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.IO.IOException
       Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
       Source=System
       StackTrace:
            at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.HttpWebRequest.MakeMemoryStream(Stream stream)
       InnerException: System.Net.Sockets.SocketException
            Message=An existing connection was forcibly closed by the remote host
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
                 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
            InnerException: 

John Carruthers

unread,
Apr 22, 2011, 11:13:10 PM4/22/11
to servic...@googlegroups.com
Even more interesting, accessing a service directly and using GET to pass arguments works.
It appears to be just using POST with XML/JSON/JSV breaks it :/

Demis Bellot

unread,
Apr 22, 2011, 11:13:52 PM4/22/11
to servic...@googlegroups.com
Hi John,

You can inject your own logging by setting a global error handler, e.g:

LogHander.LogFactory = new ConsoleLogFactory();

There are a few different logging providers supported including Debug, Log4Net and EventLog providers available at:

Although if older clients work and you're not getting an exception on the wire than it doesn't sound like it's a server error. I would try the same code in a Console Application or Unit Test to see if it works. 

The best tools I've found to debug web service exceptions is Fiddler and/or WireShark which will both provide a better idea of what's happening. 
Also you should have the .pdb's in addition to the ServiceStack.dll's so I would use that to be able to debug the server, and if there is an exception on the server, you should be able to catch/debug it.

If you can give that a go and let me know a little closer to what the error could be. 

Cheers,
Demis

Demis Bellot

unread,
Apr 22, 2011, 11:17:10 PM4/22/11
to servic...@googlegroups.com
ok the difference is that in POST/PUT the DTO is serialized on the wire, i.e. JSON for JsonServiceClient, XML for XmlServiceClient, etc.
The GET and DELETE methods doesn't have any HTTP body which I imagine where the error is.

I think the Fiddler / WireShark trace is going to offer the best insight here.

D


On Sat, Apr 23, 2011 at 4:13 AM, John Carruthers <sir.kny...@gmail.com> wrote:
Even more interesting, accessing a service directly and using GET to pass arguments works.
It appears to be just using POST with XML/JSON/JSV breaks it :/



John Carruthers

unread,
Apr 22, 2011, 11:36:55 PM4/22/11
to servic...@googlegroups.com
The jury is in: Fiddler proves me to be an idiot.

I was building the XmlClientService with a URI of /servicestack/xml/syncreply and the XmlClientService was adding a second /xml/syncreply to the URI.
So I ended up calling to /servicestack/xml/syncreply/xml/syncreply

Problem solved, moving onwards and upwards :)

Demis Bellot

unread,
Apr 22, 2011, 11:49:05 PM4/22/11
to servic...@googlegroups.com
Ahh nice1 :) Well I'm glad it's solved.
As a side benefit you now know about the best tools to debug future problems.

Anyway looking forward to what you are able do with it since your StackTrace looks very interesting :)

Cheers,
Demis
Reply all
Reply to author
Forward
0 new messages