From 006dfd6d9a31127b5aad55b16b7f85f29faff620 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 2 Oct 2009 20:35:15 -0700 Subject: Closing another stream. --- .../HttpServer/SynchronousRestObjectRequester.cs | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs index ec9bd4f..eab463c 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs @@ -58,6 +58,7 @@ namespace OpenSim.Framework.Servers.HttpServer public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { Type type = typeof (TRequest); + TResponse deserial = default(TResponse); WebRequest request = WebRequest.Create(requestUrl); request.Method = verb; @@ -81,19 +82,33 @@ namespace OpenSim.Framework.Servers.HttpServer int length = (int) buffer.Length; request.ContentLength = length; - Stream requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); + Stream requestStream = null; + try + { + requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + } + catch (Exception) + { + return deserial; + } + finally + { + if (requestStream != null) + requestStream.Close(); + } } - TResponse deserial = default(TResponse); try { using (WebResponse resp = request.GetResponse()) { if (resp.ContentLength > 0) { + Stream respStream = resp.GetResponseStream(); XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); + deserial = (TResponse)deserializer.Deserialize(respStream); + respStream.Close(); } } } -- cgit v1.1