4ce51214c0e73ce94b7a0e5f7062f751c41f3f36
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / DnsEndpointIdentity.cs
1 //----------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4
5 namespace System.ServiceModel
6 {
7     using System;
8     using System.IdentityModel.Claims;
9     using System.IdentityModel.Policy;
10     using System.Xml;
11     using System.Xml.Serialization;
12
13     public class DnsEndpointIdentity : EndpointIdentity
14     {
15         public DnsEndpointIdentity(string dnsName)
16         {
17             if (dnsName == null)
18                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dnsName");
19
20             base.Initialize(Claim.CreateDnsClaim(dnsName));
21         }
22
23         public DnsEndpointIdentity(Claim identity)
24         {
25             if (identity == null)
26                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identity");
27
28             // PreSharp 
29 #pragma warning suppress 56506 // Claim.ClaimType will never return null
30             if (!identity.ClaimType.Equals(ClaimTypes.Dns))
31                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.UnrecognizedClaimTypeForIdentity, identity.ClaimType, ClaimTypes.Dns));
32
33             base.Initialize(identity);
34         }
35
36         internal override void WriteContentsTo(XmlDictionaryWriter writer)
37         {
38             if (writer == null)
39                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
40
41             writer.WriteElementString(XD.AddressingDictionary.Dns, XD.AddressingDictionary.IdentityExtensionNamespace, (string)this.IdentityClaim.Resource);
42         }
43     }
44 }