简体   繁体   English

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

[英]WCF service client configuration from appsetting.json (.NET Core)

Is there any way to configure WCF Service Reference from configuration file?有没有办法从配置文件配置 WCF 服务引用? I would like to configure WCF service reference with such settings as SecurityMode, Address, ReaderQuotas etc. I would also like to be able to choose between WsHttpBinding, BasicHttpBinding, BasicHttpsBinging etc (like normal configuration provided by app.config in .NET Framework).我想使用 SecurityMode、Address、ReaderQuotas 等设置配置 WCF 服务引用。我还希望能够在 WsHttpBinding、BasicHttpBinding、BasicHttpsBinging 等之间进行选择(如 .NET Framework 中 app.config 提供的正常配置)。

Is there any way to achive that in .NET Core/.NET Standard?有没有办法在 .NET Core/.NET Standard 中实现这一点?

Thank, Bartek谢谢,巴特克

Certain binding, such as Wshttpbinding , Netnamedbinding is not compatible with DotNet Core framework.某些绑定,例如WshttpbindingNetnamedbinding与 DotNet Core 框架不兼容。 Consequently, we could not configure it.因此,我们无法配置它。 However, this doesn't represent that we can't configure Basichttpbinding , Nettcpbinding .但是,这并不代表我们不能配置BasichttpbindingNettcpbinding
At present, the WCF service cannot be created by using DotNet Core without using the third-party library.目前,不使用第三方库,无法使用DotNet Core创建WCF服务。 Moreover, WCF client based on DotNet Core just a compatible workaround.此外,基于 DotNet Core 的 WCF 客户端只是一种兼容的解决方法。
https://github.com/dotnet/wcf https://github.com/dotnet/wcf
Like the DotNet Framework project, Microsoft Corporation provides Microsoft WCF Web Service Reference Provider tool to generate a client proxy.与 DotNet Framework 项目一样,Microsoft Corporation 提供了 Microsoft WCF Web Service Reference Provider 工具来生成客户端代理。
https://docs.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide https://docs.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
After adding connected service, it shall generate a new namespace contains the client proxy class.添加连接服务后,它会生成一个包含客户端代理类的新命名空间。 Most of the client configuration located in the Reference.cs .大多数客户端配置位于Reference.cs
Also, we could manually program the code to call the WCF service.此外,我们可以手动编写代码来调用 WCF 服务。

class Program
    {
        static void Main(string[] args)
        {
            //using the automatically generated client proxy lcoated in the Reference.cs file to call the service.
            //ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
            //var result = client.TestAsync();
            //Console.WriteLine(result.Result);

            //using the Channel Factory to call the service.
            Uri uri = new Uri("http://10.157.13.69:21012");
            BasicHttpBinding binding = new BasicHttpBinding();
            ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, new EndpointAddress(uri));
            IService service = factory.CreateChannel();
            var result = service.Test();
            Console.WriteLine(result);
        }
    }
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        string Test();

    }

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
Feel free to let me know if there is anything I can help with.如果有什么我可以帮忙的,请随时告诉我。

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

相关问题 将值保存到 appsetting..NET 核心中的 json - Saving values to appsetting.json in .NET Core 通过appsetting.json的CORS Asp.Net Core - CORS Asp.Net Core through the appsetting.json 从类库访问Asp.net-core中的appsetting.json - Access from class library to appsetting.json in Asp.net-core 在 .net core 3.1 中使用来自 appsetting.json 的凭据时,授权不起作用 - Authorization not working when using credentials from appsetting.json in .net core 3.1 appsetting.json如何在多个项目.net核心中工作? - How appsetting.json works in multiple project .net core? 如何将 appsetting.json 部分加载到 .NET Core 中的字典中? - How to load appsetting.json section into Dictionary in .NET Core? 在.NET CORE中,如何执行XUnit测试以检查和验证从AppSetting.json加载的正确信息 - In .NET CORE, How to perform XUnit test to check and validate correct information loading from AppSetting.json 使用 appsetting.json 文件中的 .NET Core 6.0 设置数据库上下文 - Setup database context using .NET Core 6.0 from appsetting.json file 作为Windows服务部署时,不会读取asp.net Core 2 Web API appsetting.json值 - asp.net Core 2 Web API appsetting.json values aren't being read when deployed as windows service 从类中的appsetting.json获取价值 - Get Value from appsetting.json in class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM