Author: atsushi
Date: 2008-02-16 04:32:58 -0500 (Sat, 16 Feb 2008)
New Revision: 95857

Modified:
   trunk/olive/samples/services/web-http-binding/ChangeLog
   trunk/olive/samples/services/web-http-binding/samplecli.cs
   trunk/olive/samples/services/web-http-binding/samplesvc.cs
Log:
2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * samplesvc.cs, samplecli.cs : added couple of complication.
          Anyways now they communicate.



Modified: trunk/olive/samples/services/web-http-binding/ChangeLog
===================================================================
--- trunk/olive/samples/services/web-http-binding/ChangeLog     2008-02-16 
09:15:00 UTC (rev 95856)
+++ trunk/olive/samples/services/web-http-binding/ChangeLog     2008-02-16 
09:32:58 UTC (rev 95857)
@@ -1,3 +1,8 @@
+2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * samplesvc.cs, samplecli.cs : added couple of complication.
+         Anyways now they communicate.
+
 2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * samplecli.cs : typo in url :(

Modified: trunk/olive/samples/services/web-http-binding/samplecli.cs
===================================================================
--- trunk/olive/samples/services/web-http-binding/samplecli.cs  2008-02-16 
09:15:00 UTC (rev 95856)
+++ trunk/olive/samples/services/web-http-binding/samplecli.cs  2008-02-16 
09:32:58 UTC (rev 95857)
@@ -1,5 +1,6 @@
 using System;
 using System.ServiceModel;
+using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
 using System.ServiceModel.Web;
 
@@ -9,20 +10,41 @@
        public static void Main ()
        {
                string url = "http://localhost:8080";;
-               WebHttpBinding b = new WebHttpBinding ();
+               //WebHttpBinding b = new WebHttpBinding ();
+               CustomBinding b = new CustomBinding (
+                       new WebMessageEncodingBindingElement (),
+                       new InterceptorBindingElement (),
+                       new HttpTransportBindingElement () { ManualAddressing = 
true });
                var f = new WebChannelFactory<IMyService> (b, new Uri (url));
                // this causes NRE (even if the endpointaddress is specified at 
CreateChannel()).
                // var f = new WebChannelFactory<IMyService> (b); 
-               f.Endpoint.Behaviors.Add (new WebHttpBehavior ());
                IMyService s = f.CreateChannel ();
                Console.WriteLine (s.Greet ("hogehoge"));
        }
 }
 
+public class InterceptorBindingElement : BindingElement
+{
+       public override T GetProperty<T> (BindingContext context)
+       {
+Console.WriteLine (context.BindingParameters.Count);
+foreach (object o in context.BindingParameters) Console.WriteLine (o.GetType 
());
+               return context.GetInnerProperty<T> ();
+               //throw new NotImplementedException ();
+       }
+
+       public override BindingElement Clone ()
+       {
+               return this;
+       }
+}
+
 [ServiceContract]
 public interface IMyService
 {
        [OperationContract]
+       //[WebGet (RequestFormat = WebMessageFormat.Json, UriTemplate = 
"/{foo}/{foo}")]
+       //[WebGet (RequestFormat = WebMessageFormat.Json)]
        [WebGet]
        string Greet (string input);
 }

Modified: trunk/olive/samples/services/web-http-binding/samplesvc.cs
===================================================================
--- trunk/olive/samples/services/web-http-binding/samplesvc.cs  2008-02-16 
09:15:00 UTC (rev 95856)
+++ trunk/olive/samples/services/web-http-binding/samplesvc.cs  2008-02-16 
09:32:58 UTC (rev 95857)
@@ -1,6 +1,8 @@
 using System;
 using System.ServiceModel;
+using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
+using System.ServiceModel.Dispatcher;
 using System.ServiceModel.Web;
 
 public class Test
@@ -11,9 +13,8 @@
                string url = "http://localhost:8080/";;
                WebHttpBinding b = new WebHttpBinding ();
                var host = new WebServiceHost (typeof (MyService), new Uri 
(url));
-               host.AddServiceEndpoint ("MyService", b, "");
-               host.Description.Behaviors.Find<ServiceDebugBehavior> 
().IncludeExceptionDetailInFaults = true;
-               host.Description.Behaviors.Find<ServiceDebugBehavior> 
().HttpHelpPageEnabled = true;
+               ServiceEndpoint se = host.AddServiceEndpoint ("MyService", b, 
"");
+               se.Behaviors.Add (new MyWebBehavior ());
                host.Open ();
                Console.WriteLine ("--- enter ---");
                Console.ReadLine ();
@@ -21,13 +22,87 @@
        }
 }
 
+public class MySelector : WebHttpDispatchOperationSelector
+{
+       public MySelector (ServiceEndpoint se)
+               : base (se)
+       {
+               endpoint = se;
+       }
+
+       ServiceEndpoint endpoint;
+
+       protected override string SelectOperation (ref Message message, out 
bool uriMatched)
+       {
+               /*
+               foreach (OperationDescription od in 
endpoint.Contract.Operations)
+                       foreach (object obj in od.Behaviors)
+                               Console.WriteLine (obj);
+               Console.WriteLine ("Message: " + message);
+               Console.WriteLine ("To: " + message.Headers.To);
+               foreach (string s in message.Properties.Keys)
+                       Console.WriteLine ("{0}: {1}", s, message.Properties 
[s]);
+               HttpRequestMessageProperty p = message.Properties 
[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
+               Console.WriteLine ("p.QueryString: {0}", p.QueryString);
+               foreach (string s in p.Headers.Keys)
+                       Console.WriteLine ("{0}: {1}", s, p.Headers [s]);
+               */
+               string ret = base.SelectOperation (ref message, out uriMatched);
+               // Console.WriteLine ("{0} {1}", ret, uriMatched);
+               // Console.WriteLine ("_____________________");
+               return ret;
+       }
+}
+
+public class MyWebBehavior : WebHttpBehavior
+{
+       public override void ApplyDispatchBehavior(ServiceEndpoint endpoint, 
EndpointDispatcher endpointDispatcher)
+       {
+               base.ApplyDispatchBehavior (endpoint, endpointDispatcher);
+Console.WriteLine (endpointDispatcher.AddressFilter);
+               endpointDispatcher.AddressFilter = new 
MyEndpointAddressMessageFilter (endpoint.Address);
+       }
+
+       protected override WebHttpDispatchOperationSelector 
GetOperationSelector (ServiceEndpoint endpoint)
+       {
+               return new MySelector (endpoint);
+       }
+}
+
+//public class MyEndpointAddressMessageFilter : EndpointAddressMessageFilter
+public class MyEndpointAddressMessageFilter : 
PrefixEndpointAddressMessageFilter
+{
+       public MyEndpointAddressMessageFilter (EndpointAddress ea)
+               : base (ea)
+       {
+       }
+       protected override IMessageFilterTable<FilterData> 
CreateFilterTable<FilterData> ()
+       {
+               //throw new Exception ();
+               return base.CreateFilterTable<FilterData> ();
+       }
+
+       public override bool Match (Message message)
+       {
+               Console.WriteLine ("*** To: " + message.Headers.To);
+               return base.Match (message);
+       }
+
+       public override bool Match (MessageBuffer buffer)
+       {
+               Console.WriteLine (buffer.CreateMessage ().Headers.To);
+               return base.Match (buffer);
+       }
+}
+
 [ServiceContract]
 public class MyService
 {
        [OperationContract]
-       [WebGet]
+       [WebGet (RequestFormat = WebMessageFormat.Json, ResponseFormat = 
WebMessageFormat.Json)]
        public string Greet (string input)
        {
+               Console.WriteLine ("Input: " + input);
                return "huh? " + input;
        }
 }

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

Reply via email to