Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Description / ServiceEndpoint.cs
index 4ca4dd9555aae90c36c5de2a03b4cbcee71a018d..9850f3c39516763d4651f8c159cdf9fbb40e2b47 100644 (file)
 //
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Dispatcher;
 
 namespace System.ServiceModel.Description
 {
+       [DebuggerDisplay ("Name={name}")]
+       [DebuggerDisplay ("Address={address}")]
        public class ServiceEndpoint
        {
                ContractDescription contract;
@@ -66,6 +69,13 @@ namespace System.ServiceModel.Description
 
                public ContractDescription Contract {
                        get { return contract; }
+#if NET_4_0
+                       set {
+                               if (value == null)
+                                       throw new ArgumentNullException ("value");
+                               contract = value;
+                       }
+#endif
                }
 
                public EndpointAddress Address {
@@ -109,8 +119,11 @@ namespace System.ServiceModel.Description
                        set { name = value; }
                }
 
-               internal void Validate () {
-#if !NET_2_1
+               internal void Validate ()
+               {
+                       if (Contract.Operations.Count == 0)
+                               throw new InvalidOperationException (String.Format ("ContractDescription '{0}' has zero operations; a contract must have at least one operation.", Contract.ContractType.Name));
+
                        foreach (IContractBehavior b in Contract.Behaviors)
                                b.Validate (Contract, this);
                        foreach (IEndpointBehavior b in Behaviors)
@@ -119,7 +132,6 @@ namespace System.ServiceModel.Description
                                foreach (IOperationBehavior b in operation.Behaviors)
                                        b.Validate (operation);
                        }
-#endif
                }
 
 
@@ -129,12 +141,11 @@ namespace System.ServiceModel.Description
 
                        var proxy = se.Contract.CreateClientRuntime (callbackDispatchRuntime);
 
-#if !NET_2_1
                        foreach (IEndpointBehavior b in se.Behaviors)
                                b.ApplyClientBehavior (se, proxy);
                        foreach (IContractBehavior b in se.Contract.Behaviors)
                                b.ApplyClientBehavior (se.Contract, se, proxy);
-#endif
+
                        return proxy;
                }
        }