微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.Net Core 中的 Http 绑定使用带有 wcf 参考的库项目

如何解决.Net Core 中的 Http 绑定使用带有 wcf 参考的库项目

我的 .net core 3.1 项目引用了一个在 .Net Framework 3.5 中构建的类库项目。 库项目有一个 wcf 服务引用,其绑定在 app.config 中定义。

在 dotnet 框架中,我们通常在消费项目中提供 http 绑定。

当我尝试在 dotnet 核心(消费项目)的 app.config 中手动添加服务绑定时,出现此错误 - “无法识别的配置部分 system.serviceModel

有什么方法可以在引用库项目的项目中提供 http 绑定。

更新 1

这是我在 dotnet 核心项目中的 app.config -

   <?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
        <add key="username" value="usr"/>
        <add key="password" value="pass"/>
        <add key="logPath" value="c:\test\api_log.txt"/>    
    </appSettings>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="ListManagementSoap">
                    <security mode="Transport" />
                </binding>
                <binding name="ListManagementSoap1" />
                <binding name="ContactManagementSoap">
                    <security mode="Transport" />
                </binding>
                <binding name="ContactManagementSoap1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://ws.caigners.com/listmanagement.asmx"
                binding="basicHttpBinding" bindingConfiguration="ListManagementSoap"
                contract="ListManagementAPI.ListManagementSoap" name="ListManagementSoap" />
            <endpoint address="https://ws.caigners.com/contactmanagement.asmx"
                binding="basicHttpBinding" bindingConfiguration="ContactManagementSoap"
                contract="ContactManagementAPI.ContactManagementSoap" name="ContactManagementSoap" />
        </client>
    </system.serviceModel>
</configuration>

解决方法

.net core 目前不支持创建 WCF 服务,但您可以在 .net core 中创建 WCF 客户端来调用 WCF 服务。虽然可以在 .net core 中调用 WCF 服务,但是会受到一些限制。 .net Core 中的 WCF 客户端仅支持四种绑定:BasicHttpBinding、CustomBinding、NetHttpBinding、NetTcpBinding,.net Core 中的安全特性并不多。

enter image description here

如果要识别system.serviceModel,需要安装System.ServiceModel.Http。有关它的更多信息,您可以参考此link

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。