Connection closing unexpectedly when posting to web service

Connection closing unexpectedly when posting to web service SearchSearch
Author Message
Toby Wright
Unregistered guest
Posted on Monday, October 24, 2005 - 02:23 pm:   

Hi,

I'm writing code to programmatically send MMS by POSTing to the NowMMS web service. The MMSs I am trying to send consists of a phone number, subject and jpeg image file. I have a MC35 and I can confirm that the settings and the web services are running correctly by manually using the "Send MMS Message" page. When I use that page of the web service to send an MMS it works perfectly every time. However when I use my code to POST to the URL of the web service (http://localhost:8801/ on my setup) it works only intermittently.

My code is written in .NET C# and follows the advice of various posts on these forums as to how to construct a multipart form POST message for sending the contents of an MMS to the NowMMS web service. When I was using NowMMS v5.51b the code would work reasonably often but on occasion return:

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

This occurred when I called GetResponse on the HttpWebRequest object, which is the point at which the connection is made and the POST data sent. Further investigation using a proxy informed me that immediately after the data being posted had been sent to the NowMMS web service the connection was closed by the web service end without any response.

I upgraded to v5.51k just in case and now the behaviour has changed. It still occasionally works, but less often than previously, and it still sometimes simply closes the connection. However most often I get the error:

System.IO.IOException: Unable to write data to the transport connection.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
at System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)

This occurs when I try to write a byte to the stream I am using to POST to, but not usually on the first byte being written.

I have tried tweaking my code in a variety of ways, playing with header fields, timeouts and the like, but without seeing any change in behaviour. I have also tried sending exactly the same post twice in a row and have seen it work once and fail once.

Do you have any idea what my code might be doing that causes the web service to react like this?

Yours,

Toby Wright
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 5293
Registered: 10-2002
Posted on Thursday, December 01, 2005 - 08:58 pm:   

Toby,

Sorry that I missed this posting when it was originally posted.

My guess is that the "Content-Length:" header is not set correctly. We were waiting for more content, but it was never received, so we closed the connection. Or we received a request without a "Content-Length:" header and the truncated data was invalid.

The best way to see if this is what is happening is to enable the debug logs in NowSMS (the easiest way to do this is to use the checkboxes on the "Serial #" page of the configuration dialog).

Do you see "Incomplete request" in the log?

An Ethereal trace might also be helpful.


-bn