Add IdentityElement implementation and some supplemental extension methods for discovery.
authorAtsushi Eno <atsushi@ximian.com>
Wed, 1 Sep 2010 09:53:46 +0000 (18:53 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Wed, 1 Sep 2010 09:53:46 +0000 (18:53 +0900)
mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs
mcs/class/System.ServiceModel/System.ServiceModel.Configuration/IdentityElement.cs

index 5a5ab97a25ebba46edfd3dfea0be1ba64caac11b..1786a93db541642509c4dadc1be9256272fe8688 100644 (file)
@@ -100,6 +100,30 @@ namespace System.ServiceModel.Configuration
                        return new EndpointAddress (el.Address, el.Identity.CreateInstance (), el.Headers.Headers);
                }
 
+               public static void CopyFrom (this ChannelEndpointElement to, ChannelEndpointElement from)
+               {
+                       to.Address = from.Address;
+                       to.BehaviorConfiguration = from.BehaviorConfiguration;
+                       to.Binding = from.Binding;
+                       to.BindingConfiguration = from.BindingConfiguration;
+                       to.Contract = from.Contract;
+                       if (from.Headers != null)
+                               to.Headers.Headers = from.Headers.Headers;
+                       if (from.Identity != null)
+                               to.Identity.InitializeFrom (from.Identity.CreateInstance ());
+                       to.Name = from.Name;
+               }
+
+               public static EndpointAddress CreateEndpointAddress (this ChannelEndpointElement el)
+               {
+                       return new EndpointAddress (el.Address, el.Identity != null ? el.Identity.CreateInstance () : null, el.Headers.Headers);
+               }
+
+               public static EndpointAddress CreateEndpointAddress (this ServiceEndpointElement el)
+               {
+                       return new EndpointAddress (el.Address, el.Identity != null ? el.Identity.CreateInstance () : null, el.Headers.Headers);
+               }
+
                public static EndpointIdentity CreateInstance (this IdentityElement el)
                {
                        if (el.Certificate != null)
index 3859aaab2db9908e6b8afac48a2f2aacb44b6452..cd94210b92e23040662f8eafeba357b7c511acdf 100644 (file)
@@ -32,6 +32,7 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Configuration;
+using System.Linq;
 using System.Net;
 using System.Net.Security;
 using System.Reflection;
@@ -99,24 +100,29 @@ namespace System.ServiceModel.Configuration
                        get { return (UserPrincipalNameElement) base ["userPrincipalName"]; }
                }
 
-
+               // it was extraneous...
                internal EndpointIdentity Create ()
                {
-                       if (Certificate != null && !String.IsNullOrEmpty (Certificate.EncodedValue))
-                               return new X509CertificateEndpointIdentity (new X509Certificate2 (Convert.FromBase64String (Certificate.EncodedValue)));
-                       if (CertificateReference != null && !String.IsNullOrEmpty (CertificateReference.FindValue))
-                               // FIXME: imeplement
-                               throw new NotImplementedException ();
-                       if (Dns != null && !String.IsNullOrEmpty (Dns.Value))
-                               return new DnsEndpointIdentity (Dns.Value);
-                       if (Rsa != null && !String.IsNullOrEmpty (Rsa.Value))
-                               return new RsaEndpointIdentity (Rsa.Value);
-                       if (ServicePrincipalName != null && !String.IsNullOrEmpty (ServicePrincipalName.Value))
-                               return new SpnEndpointIdentity (ServicePrincipalName.Value);
-                       if (UserPrincipalName != null && !String.IsNullOrEmpty (UserPrincipalName.Value))
-                               return new UpnEndpointIdentity (UserPrincipalName.Value);
+                       return ConfigUtil.CreateInstance (this);
+               }
+
+               public void InitializeFrom (EndpointIdentity identity)
+               {
+                       if (identity == null)
+                               throw new ArgumentNullException ("identity");
 
-                       return null;
+                       if (identity is X509CertificateEndpointIdentity)
+                               Certificate.EncodedValue = Convert.ToBase64String (((X509CertificateEndpointIdentity) identity).Certificates [0].RawData);
+                       else if (identity is DnsEndpointIdentity)
+                               Dns.Value = (string) ((DnsEndpointIdentity) identity).IdentityClaim.Resource;
+                       else if (identity is RsaEndpointIdentity)
+                               Rsa.Value = (string) ((RsaEndpointIdentity) identity).IdentityClaim.Resource;
+                       else if (identity is SpnEndpointIdentity)
+                               ServicePrincipalName.Value = (string) ((SpnEndpointIdentity) identity).IdentityClaim.Resource;
+                       else if (identity is UpnEndpointIdentity)
+                               UserPrincipalName.Value = (string) ((UpnEndpointIdentity) identity).IdentityClaim.Resource;
+                       else
+                               throw new ArgumentException (String.Format ("Unexpected EndpointIdentity of type '{0}'", identity.GetType ()));
                }
        }