[英]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.某些绑定,例如
Wshttpbinding
、 Netnamedbinding
与 DotNet Core 框架不兼容。 Consequently, we could not configure it.因此,我们无法配置它。 However, this doesn't represent that we can't configure
Basichttpbinding
, Nettcpbinding
.但是,这并不代表我们不能配置
Basichttpbinding
、 Nettcpbinding
。
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.