这是我第一次创建WCF服务。我需要使用HTTPS,因为我将使用MembershipBinding。我采取的步骤是:
我现在正在使用WCF测试客户端测试服务,但我收到消息:
错误:无法从https://localhost:444/Service.svc获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange错误URI上的MSDN文档:https://localhost:444/Service.svc元数据包含无法解析的引用:' https://localhost:444/Service.svc'。无法使用权限&localhost:444'建立SSL / TLS安全通道的信任关系。底层连接已关闭:无法为SSL / TLS安全通道建立信任关系。根据验证程序,远程证书无效.HTTP GET错误URI:https://localhost:444/Service.svc下载' https://localhost:444/Service.svc'时出错。底层连接已关闭:无法为SSL / TLS安全通道建立信任关系。根据验证程序,远程证书无效。
该错误表明存在信任证书的问题,但我信任用于创建证书的证书颁发机构,因此我不知道如何解决它。当我使用http时,该服务工作正常。
提前致谢。
答案 0 :(得分:0)
由于您的证书是自签名的,因此您需要在客户呼叫中添加黑客攻击:
using (MyWCFServiceClient client = new MyWCFServiceClient())
{
#if DEBUG
ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificatesCallback;
#endif
client.MyCall();
}
TrustAllCertificatesCallback的定义:
internal static bool TrustAllCertificatesCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
{
bool isValid = true;
// TODO logic to check your self-signed certifiacte
return isValid;
}
应该在生产环境中停用TrustAllCertificatesCallback回调。