* HttpRequestChannel.cs: if the response has no body, create an
authorAndreia Gaita <avidigal@novell.com>
Wed, 19 May 2010 05:10:16 +0000 (05:10 -0000)
committerAndreia Gaita <avidigal@novell.com>
Wed, 19 May 2010 05:10:16 +0000 (05:10 -0000)
  empty message and return that.
  Note: the ws-mc protocol defines that the service returns an
  200 response with an empty body on first connection, this
  adds support for that (fixes part of #599667)

svn path=/trunk/mcs/; revision=157525

mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpRequestChannel.cs

index 05ebc63f503009742ae9221b9692f2d3f5c098a3..4b16a1c458a733ae82d469db3588ae82ee03ddbd 100755 (executable)
@@ -1,3 +1,11 @@
+2010-05-19  Andreia Gaita  <avidigal@novell.com>
+
+       * HttpRequestChannel.cs: if the response has no body, create an
+         empty message and return that.
+         Note: the ws-mc protocol defines that the service returns an
+         200 response with an empty body on first connection, this
+         adds support for that (fixes part of #599667)
+
 2010-05-14  Atsushi Enomoto  <atsushi@ximian.com>
 
        * DuplexChannelBase.cs
index 137ef534d2d32777ccdd4f8777aa4b7de10afca4..5428146382bb07857d4f18190facd1c2963f91f0 100644 (file)
@@ -210,25 +210,37 @@ Console.WriteLine (mb.CreateMessage ());
                        }
 
                        try {
-                               using (var responseStream = resstr) {
-                                       MemoryStream ms = new MemoryStream ();
-                                       byte [] b = new byte [65536];
-                                       int n = 0;
-
-                                       while (true) {
-                                               n = responseStream.Read (b, 0, 65536);
-                                               if (n == 0)
-                                                       break;
-                                               ms.Write (b, 0, n);
+                               Message ret;
+
+                               // TODO: unit test to make sure an empty response never throws
+                               // an exception at this level
+                               if (hrr.ContentLength == 0) {
+                                       ret = Message.CreateMessage (MessageVersion.Default, String.Empty);
+                               } else {
+
+                                       using (var responseStream = resstr) {
+                                               MemoryStream ms = new MemoryStream ();
+                                               byte [] b = new byte [65536];
+                                               int n = 0;
+
+                                               while (true) {
+                                                       n = responseStream.Read (b, 0, 65536);
+                                                       if (n == 0)
+                                                               break;
+                                                       ms.Write (b, 0, n);
+                                               }
+                                               ms.Seek (0, SeekOrigin.Begin);
+
+                                               ret = Encoder.ReadMessage (
+                                                       ms, (int) source.Transport.MaxReceivedMessageSize, res.ContentType);
                                        }
-                                       ms.Seek (0, SeekOrigin.Begin);
-
-                                       Message ret = Encoder.ReadMessage (
-                                               ms, (int) source.Transport.MaxReceivedMessageSize, res.ContentType);
-                                       var rp = new HttpResponseMessageProperty () { StatusCode = hrr.StatusCode, StatusDescription = hrr.StatusDescription };
-                                       foreach (var key in hrr.Headers.AllKeys)
-                                               rp.Headers [key] = hrr.Headers [key];
-                                       ret.Properties.Add (HttpResponseMessageProperty.Name, rp);
+                               }
+
+                               var rp = new HttpResponseMessageProperty () { StatusCode = hrr.StatusCode, StatusDescription = hrr.StatusDescription };
+                               foreach (var key in hrr.Headers.AllKeys)
+                                       rp.Headers [key] = hrr.Headers [key];
+                               ret.Properties.Add (HttpResponseMessageProperty.Name, rp);
+
 /*
 MessageBuffer buf = ret.CreateBufferedCopy (0x10000);
 ret = buf.CreateMessage ();
@@ -237,9 +249,8 @@ w.Formatting = System.Xml.Formatting.Indented;
 buf.CreateMessage ().WriteMessage (w);
 w.Close ();
 */
-                                       channelResult.Response = ret;
-                                       channelResult.Complete ();
-                               }
+                               channelResult.Response = ret;
+                               channelResult.Complete ();
                        } catch (Exception ex) {
                                channelResult.Complete (ex);
                        } finally {