简体   繁体   English

带有 .NET 标准 2.0 的 WCF Web 服务参考

[英]WCF Web Service Reference with .NET standard 2.0

I am generating a WCF Web Service Reference reference.cs in a .NET Standard 2.0 project then using it from a .NET 4.7.1 project but I get "Could not establish secure channel for SSL/TLS with authority"我在 .NET Standard 2.0 项目中生成 WCF Web 服务参考reference.cs ,然后从 .NET 4.7.1 项目使用它,但我得到"Could not establish secure channel for SSL/TLS with authority"

If I generate it using Add Service Reference aside from visual studio 2015. I get a similar reference.cs class and if I copy it in my .NET standard 2.0 project that would work but I lose the Async call implementation of the WCF Web service.如果我使用 Visual Studio 2015 之外的Add Service Reference生成它。我得到一个类似的 reference.cs 类,如果我将它复制到我的 .NET 标准 2.0 项目中,但我会丢失 WCF Web 服务的异步调用实现。 Is there any way to make this work ?有什么办法可以使这项工作?

Make sure you configure the Bindings.确保配置绑定。 They are in the app.config in a .net framework project but should be encapsuled in a BasicHttpBinding in .NET Standard/.NET Core.它们位于 .net 框架项目的 app.config 中,但应封装在 .NET Standard/.NET Core 中的BasicHttpBinding中。

That way you can specify the security settings as needed:这样您就可以根据需要指定安全设置:

    binding.Security.Mode = BasicHttpSecurityMode.Transport;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
    binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

From Nuget package System.ServiceModel.Http:从 Nuget 包 System.ServiceModel.Http:

namespace System.ServiceModel
{
    public class BasicHttpBinding : HttpBindingBase
    {
        public BasicHttpBinding();
        public BasicHttpBinding(BasicHttpSecurityMode securityMode);

        public BasicHttpSecurity Security { get; set; }

        public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingParameterCollection parameters);
        public override BindingElementCollection CreateBindingElements();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM