appsetting.json 中的 WCF 服务客户端配置(.NET Core)

Bar*_*yży 7 .net c# wcf .net-core

有没有办法从配置文件配置WCF服务引用?我想使用 SecurityMode、Address、ReaderQuotas 等设置来配置 WCF 服务引用。我还希望能够在 WsHttpBinding、BasicHttpBinding、BasicHttpsBinging 等之间进行选择(就像 .NET Framework 中 app.config 提供的正常配置一样)。

有没有办法在 .NET Core/.NET Standard 中实现这一目标?

谢谢,巴特克

Abr*_*ian 2

某些绑定(例如WshttpbindingNetnamedbinding与 DotNet Core 框架不兼容。因此,我们无法配置它。然而,这并不代表我们可以配置Basichttpbinding, Nettcpbinding
\n目前不使用第三方库,无法使用DotNet Core创建WCF服务。而且,基于DotNet Core的WCF客户端只是一个兼容的解决方法。
\n https://github.com/dotnet/wcf
\n与 DotNet Framework 项目一样,Microsoft Corporation 提供了 Microsoft WCF Web Service Reference Provider 工具来生成客户端代理。
\n https://learn.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
\n添加连接的服务后,应生成一个包含客户端代理类的新命名空间。大多数客户端配置位于Reference.cs.
\n此外,我们可以手动编写代码来调用WCF服务。

\n\n
class Program\n    {\n        static void Main(string[] args)\n        {\n            //using the automatically generated client proxy lcoated in the Reference.cs file to call the service.\n            //ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();\n            //var result = client.TestAsync();\n            //Console.WriteLine(result.Result);\n\n            //using the Channel Factory to call the service.\n            Uri uri = new Uri("http://10.157.13.69:21012");\n            BasicHttpBinding binding = new BasicHttpBinding();\n            ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, new EndpointAddress(uri));\n            IService service = factory.CreateChannel();\n            var result = service.Test();\n            Console.WriteLine(result);\n        }\n    }\n    [ServiceContract]\n    public interface IService\n    {\n        [OperationContract]\n        string Test();\n\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
\n如果有什么我可以帮忙的,请随时告诉我。

\n

  • 我不知道这方面的一些官方实现,但下面的链接可能对您有帮助。https://www.seeleycoder.com/blog/using-wcf-with-dotnetcore/,/sf/ask/3112346541/ -启动-cs (2认同)