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

Ric*_*ett 1 .net c# wcf basichttpbinding

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

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

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

<identity>
  <dns value="Some Value" />
</identity>
Run Code Online (Sandbox Code Playgroud)

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

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

Ric*_*ett 7

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

DnsEndpointIdentity identity = new DnsEndpointIdentity("Some value");
Run Code Online (Sandbox Code Playgroud)