2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 14 Jul 2010 18:24:54 +0000 (18:24 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 14 Jul 2010 18:24:54 +0000 (18:24 -0000)
* WebMessageEncoder.cs : support Raw message in ReadMessage() too.
  Allow null content type.

* WebMessageFormatter.cs : do not depend on WebOperationContext.
  add support for Raw format request.

* WebMessageEncodingBindingElementTest.cs : add test for null
  content type for ReadMessage() (allowed),

* WebHttpBehaviorTest.cs : add test for deserializing Raw request
  message too.

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

mcs/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/WebMessageEncodingBindingElementTest.cs
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/ChangeLog
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/WebHttpBehaviorTest.cs

index 53703ef5c1ab7c4513b5ec53aae140a81a104168..1a394476d7620f8a23a32f8fe636fcf20825d8da 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * WebMessageEncoder.cs : support Raw message in ReadMessage() too.
+         Allow null content type.
+
 2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
 
        * WebMessageEncoder.cs : support Raw message. Fixed bug #619542.
index 700ea9fab75d2770db012f53b9e932d7bc97e6e3..736ad0c6beba1413586f05fc1e41be80bd6af58b 100644 (file)
@@ -73,8 +73,8 @@ namespace System.ServiceModel.Channels
                {
                        if (stream == null)
                                throw new ArgumentNullException ("stream");
-                       if (contentType == null)
-                               throw new ArgumentNullException ("contentType");
+
+                       contentType = contentType ?? "application/octet-stream";
 
                        Encoding enc = Encoding.UTF8;
                        ContentType ct = new ContentType (contentType);
@@ -92,7 +92,7 @@ namespace System.ServiceModel.Channels
                                case "application/xml":
                                        fmt = WebContentFormat.Xml;
                                        break;
-                               case "application/octet-stream":
+                               default:
                                        fmt = WebContentFormat.Raw;
                                        break;
                                }
@@ -116,7 +116,9 @@ namespace System.ServiceModel.Channels
                                wp = new WebBodyFormatMessageProperty (WebContentFormat.Json);
                                break;
                        case WebContentFormat.Raw:
-                               throw new NotImplementedException ();
+                               msg = new WebMessageFormatter.RawMessage (stream);
+                               wp = new WebBodyFormatMessageProperty (WebContentFormat.Raw);
+                               break;
                        default:
                                throw new SystemException ("INTERNAL ERROR: cannot determine content format");
                        }
index 0110de19f4d2824ffd9cc3b054b66cd88e354ef8..7bb676199a99c7ed80a526ea0a65d51314c5eb47 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * WebMessageFormatter.cs : do not depend on WebOperationContext.
+         add support for Raw format request.
+
 2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
 
        * WebMessageFormatter.cs : add support for Raw format.
index 7d3180da0e7699b6bcb737a0032ddb66491315a3..b633c9ecf2579f6ca5eb0084386387dada1a4d10 100644 (file)
@@ -499,16 +499,26 @@ namespace System.ServiceModel.Dispatcher
                                        throw new ArgumentNullException ("parameters");
                                CheckMessageVersion (message.Version);
 
-                               OperationContext.Current.Extensions.Add (new WebOperationContext (OperationContext.Current));
-
-                               IncomingWebRequestContext iwc = WebOperationContext.Current.IncomingRequest;
+                               IncomingWebRequestContext iwc = null;
+                               if (OperationContext.Current != null) {
+                                       OperationContext.Current.Extensions.Add (new WebOperationContext (OperationContext.Current));
+                                       iwc = WebOperationContext.Current.IncomingRequest;
+                               }
+                               
+                               var wp = message.Properties [WebBodyFormatMessageProperty.Name] as WebBodyFormatMessageProperty;
+                               if (wp != null && wp.Format == WebContentFormat.Raw) {
+                                       var rmsg = (RawMessage) message;
+                                       parameters [0] = rmsg.Stream;
+                                       return;
+                               }
 
                                Uri to = message.Headers.To;
                                UriTemplateMatch match = UriTemplate.Match (Endpoint.Address.Uri, to);
                                if (match == null)
                                        // not sure if it could happen
                                        throw new SystemException (String.Format ("INTERNAL ERROR: UriTemplate does not match with the request: {0} / {1}", UriTemplate, to));
-                               iwc.UriTemplateMatch = match;
+                               if (iwc != null)
+                                       iwc.UriTemplateMatch = match;
 
                                MessageDescription md = GetMessageDescription (MessageDirection.Input);
 
index 49e9e3aacb9424e73f2c4dfb70610d56efce1393..ac11387fa1a624295677ac36b4fe8f0b5801602e 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * WebMessageEncodingBindingElementTest.cs : add test for null
+         content type for ReadMessage() (allowed),
+
 2010-06-22  Atsushi Enomoto  <atsushi@ximian.com>
 
        * WebMessageEncodingBindingElementTest.cs : add test for
index b4569a953d6e4f6201b158344bce05bfb2f575f4..eabf1e3d82708c9c02f3084cfa73c35dd11186e4 100644 (file)
@@ -146,5 +146,12 @@ namespace MonoTests.System.ServiceModel
                        var bc = new BindingContext (new CustomBinding (), new BindingParameterCollection ());
                        Assert.AreEqual (MessageVersion.None, m.GetProperty<MessageVersion> (bc), "#1");
                }
+
+               [Test]
+               public void ReadMessageNullContentType ()
+               {
+                       var e = CreateEncoder ();
+                       e.ReadMessage (new MemoryStream (), 10, null);
+               }
        }
 }
index 6c2a20b9bfac22b0787306795547fc619f81a105..b32d2fa4b2fe1ea2912dc59490a3a52519cfe280 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * WebHttpBehaviorTest.cs : add test for deserializing Raw request
+         message too.
+
 2010-07-14  Atsushi Enomoto  <atsushi@ximian.com>
 
        * WebHttpBehaviorTest.cs : add test for bug #619542 (not sure if it
index 009ba909588b97c5ce13553181b2570306bcaaab..1267d08d460a34c3af6088f0d4f467027b8398d2 100644 (file)
@@ -193,6 +193,7 @@ namespace MonoTests.System.ServiceModel.Description
                [Test]
                public void MessageFormatterSupportsRaw ()
                {
+                       // serializing reply
                        var ms = new MemoryStream ();
                        var bytes = new byte [] {0, 1, 2, 0xFF};
                        ms.Write (bytes, 0, bytes.Length);
@@ -213,6 +214,26 @@ namespace MonoTests.System.ServiceModel.Description
                        wme.WriteMessage (msg, ms2);
                        Assert.AreEqual (bytes, ms2.ToArray (), "#3");
                }
+
+               [Test]
+               public void MessageFormatterSupportsRaw2 ()
+               {
+                       // deserializing request
+                       var ms = new MemoryStream ();
+                       ms.Write (new byte [] {0, 1, 2, 0xFF}, 0, 4);
+                       ms.Position = 0;
+                       var cd = ContractDescription.GetContract (typeof (ITestService));
+                       var od = cd.Operations [0];
+                       var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
+                       var wmebe = new WebMessageEncodingBindingElement ();
+                       var wme = wmebe.CreateMessageEncoderFactory ().Encoder;
+       Console.WriteLine (wme.MediaType);
+                       var msg = wme.ReadMessage (ms, 100, null); // "application/xml" causes error.
+                       var formatter = new WebHttpBehaviorExt ().DoGetRequestDispatchFormatter (od, se);
+                       object [] pars = new object [1];
+                       formatter.DeserializeRequest (msg, pars);
+                       Assert.IsTrue (pars [0] is Stream, "ret");
+               }
        }
 
        [ServiceContract]