c# - 带有 .NET 标准 2.0 的 WCF Web 服务参考
问题描述
我reference.cs
在 .NET Standard 2.0 项目中生成 WCF Web 服务引用,然后从 .NET 4.7.1 项目中使用它,但我得到了"Could not establish secure channel for SSL/TLS with authority"
如果我使用Add Service Reference
Visual Studio 2015 之外的工具生成它。我得到一个类似的 reference.cs 类,如果我将它复制到我的 .NET 标准 2.0 项目中,它会起作用,但我会丢失 WCF Web 服务的异步调用实现。有什么办法可以使这项工作?
解决方案
确保配置绑定。它们位于 .net 框架项目的 app.config 中,但应封装在BasicHttpBinding
.NET Standard/.NET Core 中。
这样您就可以根据需要指定安全设置:
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
来自 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();
}
}
推荐阅读
- string - 运行时构建:在此范围内找不到字符串
- firebase - 使用“firebase init”安装 Firebase 功能模拟器后如何卸载它
- node.js - 在存储位置找不到存档:Google 函数
- javascript - 我正在尝试运行此反应本机屏幕,它会为我获取数据。当我从主屏幕单击文本时,它会运行。但它不工作
- autocad - 导入obj文件并添加纹理
- android - 颤振错误:未定义的名称'ScaffoldMessenger'
- r - 如何解析R中的python列表?
- vb.net - VB.NET 中的动态菜单
- wordpress - 脚本适用于 Wordpress 后端,但不适用于前端。请协助
- python - 从根开始在二叉树中查找路径以留下什么总和,不按我预期的那样工作