编程设置身份对WCF的EndpointAddress身份、WCF、EndpointAddress

2023-09-03 08:16:28 作者:时光熬人

我使用下面的函数来创建一个 System.ServiceModel.EndpointAddress 连接到WCF服务时:

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;
}

我需要通过在 EndPointIdentity ,与从我的web.config以下摘录相关:

I need to pass in an EndPointIdentity that correlates with the following excerpt from my web.config:

<identity>
  <dns value="Some Value" />
</identity>

我的WCF服务使用X509证书,如此看来,我的身份必须是类型 X509CertificateEndpointIdentity 。的构造,这需要我传递一个证书......但我想传递给它一个DNS值,如上图所示。

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?

推荐答案

其实我需要创建一个DnsEndpointIdentity,如下:

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

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