* 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
+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.
{
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);
case "application/xml":
fmt = WebContentFormat.Xml;
break;
- case "application/octet-stream":
+ default:
fmt = WebContentFormat.Raw;
break;
}
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");
}
+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.
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);
+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
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);
+ }
}
}
+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
[Test]
public void MessageFormatterSupportsRaw ()
{
+ // serializing reply
var ms = new MemoryStream ();
var bytes = new byte [] {0, 1, 2, 0xFF};
ms.Write (bytes, 0, bytes.Length);
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]