Programmatically set identity on WCF EndpointAddress

Richard Ev picture Richard Ev · Apr 28, 2009 · Viewed 9.8k times · Source

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?

Answer

Richard Ev picture Richard Ev · Apr 30, 2009

In fact I needed to create a DnsEndpointIdentity, as follows:

DnsEndpointIdentity identity = new DnsEndpointIdentity("Some value");