New tests.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / EndpointDispatcher.cs
index eecb1028fccd52dcf97489e131ee2bc951590fa9..f8568b7e0781aa9f0ae501f95c6f51326338ab59 100644 (file)
@@ -66,6 +66,8 @@ namespace System.ServiceModel.Dispatcher
                        contract_ns = contractNamespace;
 
                        dispatch_runtime = new DispatchRuntime (this);
+
+                       this.address_filter = new EndpointAddressMessageFilter (address);
                }
 
                public DispatchRuntime DispatchRuntime {
@@ -86,7 +88,7 @@ namespace System.ServiceModel.Dispatcher
                }
 
                public MessageFilter AddressFilter {
-                       get { return address_filter ?? (address_filter = new EndpointAddressMessageFilter (EndpointAddress)); }
+                       get { return address_filter; }
                        set {
                                if (value == null)
                                        throw new ArgumentNullException ("value");
@@ -111,5 +113,84 @@ namespace System.ServiceModel.Dispatcher
                        get { return filter_priority; }
                        set { filter_priority = value; }
                }
+
+               internal void InitializeServiceEndpoint (bool isCallback, Type serviceType, ServiceEndpoint se)
+               {
+                       this.ContractFilter = GetContractFilter (se.Contract);
+
+                       this.DispatchRuntime.Type = serviceType;
+                       
+                       //Build the dispatch operations
+                       DispatchRuntime db = this.DispatchRuntime;
+                       if (!isCallback && se.Contract.CallbackContractType != null) {
+                               var ccd = ContractDescriptionGenerator.GetCallbackContract (db.Type, se.Contract.CallbackContractType);
+                               db.CallbackClientRuntime = ccd.CreateClientRuntime ();
+                               db.CallbackClientRuntime.CallbackClientType = ccd.ContractType;
+                       }
+                       foreach (OperationDescription od in se.Contract.Operations)
+                               if (!db.Operations.Contains (od.Name))
+                                       PopulateDispatchOperation (db, od);
+               }
+
+               void PopulateDispatchOperation (DispatchRuntime db, OperationDescription od) {
+                       string reqA = null, resA = null;
+                       foreach (MessageDescription m in od.Messages) {
+                               if (m.Direction == MessageDirection.Input)
+                                       reqA = m.Action;
+                               else
+                                       resA = m.Action;
+                       }
+                       DispatchOperation o =
+                               od.IsOneWay ?
+                               new DispatchOperation (db, od.Name, reqA) :
+                               new DispatchOperation (db, od.Name, reqA, resA);
+                       bool no_serialized_reply = od.IsOneWay;
+                       foreach (MessageDescription md in od.Messages) {
+                               if (md.Direction == MessageDirection.Input &&
+                                       md.Body.Parts.Count == 1 &&
+                                       md.Body.Parts [0].Type == typeof (Message))
+                                       o.DeserializeRequest = false;
+                               if (md.Direction == MessageDirection.Output &&
+                                       md.Body.ReturnValue != null) {
+                                       if (md.Body.ReturnValue.Type == typeof (Message))
+                                               o.SerializeReply = false;
+                                       else if (md.Body.ReturnValue.Type == typeof (void))
+                                               no_serialized_reply = true;
+                               }
+                       }
+
+                       foreach (var fd in od.Faults)
+                               o.FaultContractInfos.Add (new FaultContractInfo (fd.Action, fd.DetailType));
+
+                       // Setup Invoker
+                       o.Invoker = new DefaultOperationInvoker (od);
+
+                       // Setup Formater
+                       o.Formatter = new OperationFormatter (od, false, false); // FIXME: pass correct isRpc, isEncoded
+
+                       if (o.Action == "*" && (o.IsOneWay || o.ReplyAction == "*")) {
+                               //Signature : Message  (Message)
+                               //          : void  (Message)
+                               //FIXME: void (IChannel)
+                               if (!o.DeserializeRequest && (!o.SerializeReply || no_serialized_reply)) // what is this double-ish check for?
+                                       db.UnhandledDispatchOperation = o;
+                       }
+
+                       db.Operations.Add (o);
+               }
+
+               MessageFilter GetContractFilter (ContractDescription cd)
+               {
+                       List<string> actions = new List<string> ();
+                       foreach (var od in cd.Operations)
+                               foreach (var md in od.Messages)
+                                       if (md.Direction == MessageDirection.Input)
+                                               if (md.Action == "*")
+                                                       return new MatchAllMessageFilter ();
+                                               else
+                                                       actions.Add (md.Action);
+
+                       return new ActionMessageFilter (actions.ToArray ());
+               }
        }
 }