Author: atsushi
Date: 2008-02-08 09:23:45 -0500 (Fri, 08 Feb 2008)
New Revision: 95251

Modified:
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncodingBindingElement.cs
   trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/WebHttpBinding.cs
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/WebMessageEncodingBindingElementTest.cs
Log:
2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * WebMessageEncodingBindingElement.cs : removed some todos.
        * WebMessageEncoder.cs : implement WriteMessage(). (Though I have no
          idea how non-xml formats can be specified.)

        * WebHttpBinding.cs : Scheme could be HTTPS.
          it implements IBindingRuntimePreferences.

        * WebMessageEncodingBindingElementTest.cs : more MessageEncoder test.



Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/ChangeLog     
2008-02-08 14:19:53 UTC (rev 95250)
+++ trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/ChangeLog     
2008-02-08 14:23:45 UTC (rev 95251)
@@ -1,3 +1,8 @@
+2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebHttpBinding.cs : Scheme could be HTTPS.
+         it implements IBindingRuntimePreferences.
+
 2008-02-06  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebHttpSecurity.cs, WebHttpBinding.cs, WebHttpSecurityMode.cs:

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/WebHttpBinding.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/WebHttpBinding.cs 
    2008-02-08 14:19:53 UTC (rev 95250)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel/WebHttpBinding.cs 
    2008-02-08 14:23:45 UTC (rev 95251)
@@ -33,7 +33,7 @@
 namespace System.ServiceModel
 {
        [MonoTODO]
-       public class WebHttpBinding : Binding
+       public class WebHttpBinding : Binding, IBindingRuntimePreferences
        {
                [MonoTODO]
                public WebHttpBinding ()
@@ -102,7 +102,7 @@
                }
 
                public override string Scheme {
-                       get { return Uri.UriSchemeHttp; }
+                       get { return Security.Mode != WebHttpSecurityMode.None 
? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
                }
 
                [MonoTODO]
@@ -140,5 +140,10 @@
 
                        return new BindingElementCollection (m, t.Clone ());
                }
+
+               [MonoTODO]
+               bool IBindingRuntimePreferences.ReceiveSynchronously {
+                       get { throw new NotImplementedException (); }
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-08 14:19:53 UTC (rev 95250)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-08 14:23:45 UTC (rev 95251)
@@ -1,5 +1,11 @@
 2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * WebMessageEncodingBindingElement.cs : removed some todos.
+       * WebMessageEncoder.cs : implement WriteMessage(). (Though I have no
+         idea how non-xml formats can be specified.)
+
+2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * WebMessageEncodingBindingElement.cs : implemented
          BuildChannelFactory() and BuildChannelListener().
 

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-08 14:19:53 UTC (rev 95250)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-08 14:23:45 UTC (rev 95251)
@@ -27,7 +27,9 @@
 //
 using System;
 using System.IO;
+using System.Runtime.Serialization.Json;
 using System.ServiceModel;
+using System.Xml;
 
 namespace System.ServiceModel.Channels
 {
@@ -63,9 +65,47 @@
                        throw new NotImplementedException ();
                }
 
+               WebContentFormat GetContentFormat ()
+               {
+                       if (source.ContentTypeMapper != null)
+                               return 
source.ContentTypeMapper.GetMessageFormatForContentType (ContentType);
+                       switch (MediaType) {
+                       case "application/xml":
+                       case "text/xml":
+                               return WebContentFormat.Xml;
+                       case "application/json":
+                       case "text/json":
+                               return WebContentFormat.Json;
+                       case "application/octet-stream":
+                               return WebContentFormat.Raw;
+                       default:
+                               return WebContentFormat.Default;
+                       }
+               }
+
                public override void WriteMessage (Message message, Stream 
stream)
                {
-                       throw new NotImplementedException ();
+                       if (message == null)
+                               throw new ArgumentNullException ("message");
+                       if (!MessageVersion.Equals (message.Version))
+                               throw new ProtocolException (String.Format 
("MessageVersion {0} is not supported", message.Version));
+                       if (stream == null)
+                               throw new ArgumentNullException ("stream");
+
+                       switch (GetContentFormat ()) {
+                       case WebContentFormat.Xml:
+                               using (XmlWriter w = 
XmlDictionaryWriter.CreateTextWriter (stream, source.WriteEncoding))
+                                       message.WriteMessage (w);
+                               break;
+                       case WebContentFormat.Json:
+                               using (XmlWriter w = 
JsonReaderWriterFactory.CreateJsonWriter (stream, source.WriteEncoding))
+                                       message.WriteMessage (w);
+                               break;
+                       case WebContentFormat.Raw:
+                               throw new NotImplementedException ();
+                       case WebContentFormat.Default:
+                               throw new SystemException ("INTERNAL ERROR: 
cannot determine content format");
+                       }
                }
 
                public override ArraySegment<byte> WriteMessage (Message 
message, int maxMessageSize, BufferManager bufferManager,

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncodingBindingElement.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncodingBindingElement.cs
  2008-02-08 14:19:53 UTC (rev 95250)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncodingBindingElement.cs
  2008-02-08 14:23:45 UTC (rev 95251)
@@ -103,7 +103,6 @@
 
                // Methods
 
-               [MonoTODO]
                public override IChannelFactory<TChannel> 
BuildChannelFactory<TChannel> (BindingContext context)
                {
                        if (context == null)
@@ -120,7 +119,6 @@
                        return context.CanBuildInnerChannelListener<TChannel> 
();
                }
 
-               [MonoTODO]
                public override IChannelListener<TChannel> 
BuildChannelListener<TChannel> (BindingContext context)
                {
                        if (context == null)

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/ChangeLog
       2008-02-08 14:19:53 UTC (rev 95250)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/ChangeLog
       2008-02-08 14:23:45 UTC (rev 95251)
@@ -1,5 +1,9 @@
 2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * WebMessageEncodingBindingElementTest.cs : more MessageEncoder test.
+
+2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * WebMessageEncodingBindingElementTest.cs : test
          CanBuildChannelFactory() and CanBuildChannelListener().
          Small test for BuildChannelFactory().

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/WebMessageEncodingBindingElementTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/WebMessageEncodingBindingElementTest.cs
 2008-02-08 14:19:53 UTC (rev 95250)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Channels/WebMessageEncodingBindingElementTest.cs
 2008-02-08 14:23:45 UTC (rev 95251)
@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.Text;
@@ -23,15 +24,41 @@
                        Assert.AreEqual (Encoding.UTF8, be.WriteEncoding, "#1");
                }
 
+               MessageEncoder CreateEncoder ()
+               {
+                       WebMessageEncodingBindingElement m = new 
WebMessageEncodingBindingElement ();
+                       return m.CreateMessageEncoderFactory ().Encoder;
+               }
+
                [Test]
                public void MessageEncoder ()
                {
-                       WebMessageEncodingBindingElement m = new 
WebMessageEncodingBindingElement ();
-                       MessageEncoder e = m.CreateMessageEncoderFactory 
().Encoder;
+                       var e = CreateEncoder ();
                        Assert.AreEqual ("application/xml", e.MediaType, "#1");
                        Assert.AreEqual ("application/xml; charset=utf-8", 
e.ContentType, "#2");
                }
 
+               [Test]
+               [ExpectedException (typeof (ProtocolException))]
+               public void MessageEncoderWriteMessageSoap12 ()
+               {
+                       var e = CreateEncoder ();
+                       e.WriteMessage (Message.CreateMessage 
(MessageVersion.Soap12, "urn:foo"), Stream.Null);
+               }
+
+               [Test]
+               public void MessageEncoderWriteMessageXml ()
+               {
+                       var e = CreateEncoder ();
+                       MemoryStream ms = new MemoryStream ();
+                       // FIXME: nothing -> "" (right now it outputs <anyType 
xsi:nil='true' ... />)
+                       //e.WriteMessage (Message.CreateMessage 
(MessageVersion.None, "urn:foo"), ms);
+                       //Assert.AreEqual ("", Encoding.UTF8.GetString 
(ms.ToArray ()));
+
+                       e.WriteMessage (Message.CreateMessage 
(MessageVersion.None, "urn:foo", 135), ms);
+                       Assert.AreEqual ("<int 
xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\";>135</int>", 
Encoding.UTF8.GetString (ms.ToArray ()));
+               }
+
                BindingContext CreateBindingContext ()
                {
                        return new BindingContext (new CustomBinding (new 
HttpTransportBindingElement () { AllowCookies = true }), new 
BindingParameterCollection ());

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to