【发布时间】:2019-12-07 01:07:05
【问题描述】:
我正在开发一项服务以在 WCF 中使用基于 SSL/TLS 凭据的安全性。端点将使用 IIS 和 HTTPS 命中。基本的 HTTP 绑定可以正常工作,但是一旦我尝试添加凭据,我就会不断收到配置错误。我在这方面花了几天时间,也阅读了很多文章,但都没有成功。
我试过了
// 后面的代码
public class specificService : myServiceType
{
public static void Configure(ServiceConfiguration configuration)
{
// define https binding (I think it should be BasicHttpsBinding as opposed to BasicHttpBinding which also supports TLS but I am unsure)
var httpsBinding = new BasicHttpsBinding
{
MaxReceivedMessageSize = int.MaxValue,
Security = new BasicHttpsSecurity
{
Mode = BasicHttpsSecurityMode.Transport,
Transport = new HttpTransportSecurity
{
ClientCredentialType = HttpClientCredentialType.Certificate
}
}
};
configuration.AddServiceEndpoint(typeof(myServiceType), httpsBinding, string.Empty);
configuration.Description.Endpoints.Find(typeof(myServiceType))?.EndpointBehaviors.Add(new myNamespace.MyCustomEndpointBehavior());
configuration.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
configuration.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
// Do I need to explicitly add my certificate?
X509Certificate2 myCert = ... get cert from local machine store
configuration.Credentials.ServiceCertificate.Certificate = myCert;
}
/* myServiceType interface */
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://somenamespace", ConfigurationName="someothernamespace.Services.myServiceType")]
public interface myServiceType
{
// CODEGEN: Generating message contract since the operation specificAction is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action="http://somenamespace/specificAction")]
someothernamespace.Services.specificActionResponse specificAction(someothernamespace.Services.specificAction request);
}
我不断收到“配置错误”,但没有详细说明我到底做错了什么。我已经尝试了不同的实现(wsHttpBindings)但没有成功。
【问题讨论】:
-
我不知道您的具体问题是什么,但我的建议是先尝试使用配置文件使其工作。一旦你有了它,你就可以将它用作如何在纯代码中完成它的模板。
标签: c# wcf ssl credentials