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 中实现这一目标?
谢谢,巴特克
某些绑定(例如Wshttpbinding)Netnamedbinding与 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服务。
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 }\nRun Code Online (Sandbox Code Playgroud)\n\nhttps://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
\n如果有什么我可以帮忙的,请随时告诉我。
| 归档时间: |
|
| 查看次数: |
10899 次 |
| 最近记录: |