1

我有一个基于 WCF 的客户端-服务器应用程序,我使用 ServiceDiscovery 从客户端查找服务器。在关闭安全性的开发过程中,发现工作正常,但是当我们基于证书打开消息安全性时,ServiceDiscovery 停止工作。

当我搜索解决方案时,我发现了这篇 MSDN 文章http://msdn.microsoft.com/en-us/library/dd456791%28v=vs.110%29.aspx其中说;

使用消息级别安全性时,必须在服务发现端点上指定 EndpointIdentity,在客户端发现端点上指定匹配的 EndpointIdentity。有关消息级别安全性的详细信息,请参阅 WCF 中的消息安全性。

我一直在搜索、阅读和编写代码,但我似乎无法将其纳入工作代码。有任何想法吗?

原始服务器代码的摘录:

private Binding CreateBinding()
{
    WSDualHttpBinding binding = new WSDualHttpBinding(WSDualHttpSecurityMode.Message);
    // Set other binding properties
    return binding;
}

private static void EnableServiceDiscovery(ServiceHostBase host)
{
    host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
    host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
}

原始客户端代码的紧凑提取:

public IEnumerable<MyServiceEndpoint> FindServicesOnNetwork()
{
    DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
    var myServiceEndpoints = discoveryClient.Find(new FindCriteria(typeof (IMyService))).Endpoints;
    discoveryClient.Close();
    return myServiceEndpoints.Select(endpoint => new MyServiceEndpoint(endpoint.Address.Uri.ToString())).ToList();
}
4

0 回答 0