Q:

Programmatically set identity on WCF EndpointAddress

I am using the following function to create a System.ServiceModel.EndpointAddress when connecting to a WCF Service:
private static EndpointAddress GetEndPointAddress(string url, EndpointIdentity identity)
{
    Uri baseAddress = new Uri(url);
    EndpointAddress endpointAddress = new EndpointAddress(
        baseAddress,
        identity,
        new AddressHeaderCollection());
    return endpointAddress;
}

I need to pass in an EndPointIdentity that correlates with the following excerpt from my web.config:
<identity>
  <dns value="Some Value" />
</identity>

My WCF Service uses an X509 certificate, so it seems that my identity needs to be of type X509CertificateEndpointIdentity. The constructor for this requires me to pass in a certificate...but I want to pass it a dns value, as shown above.
Can anyone suggest what is wrong with my approach?

A:

In fact I needed to create a DnsEndpointIdentity, as follows:
DnsEndpointIdentity identity = new DnsEndpointIdentity("Some value");

