以编程方式在WCF EndpointAddress上设置标识

我在连接到WCF服务时使用以下函数创建System.ServiceModel.EndpointAddress

 private static EndpointAddress GetEndPointAddress(string url, EndpointIdentity identity) { Uri baseAddress = new Uri(url); EndpointAddress endpointAddress = new EndpointAddress( baseAddress, identity, new AddressHeaderCollection()); return endpointAddress; } 

我需要传入一个与我的web.config中的以下摘录相关的EndPointIdentity

    

我的WCF服务使用X509证书,因此我的身份似乎必须是X509CertificateEndpointIdentity类型。 这个构造函数要求我传入证书…但我想传递一个dns值,如上所示。

任何人都可以建议我的方法有什么问题吗?

实际上我需要创建一个DnsEndpointIdentity,如下所示:

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