编程设置身份对WCF的EndpointAddress [英] Programmatically set identity on WCF EndpointAddress

查看:465
本文介绍了编程设置身份对WCF的EndpointAddress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的函数来创建一个 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");

这篇关于编程设置身份对WCF的EndpointAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆