小编439*_*439的帖子

如何将值更新到appsetting.json?

我正在使用官方文档中IOptions描述的模式.

当我从中读取值时appsetting.json,这可以正常工作,但是如何更新值并将更改保存回来appsetting.json

在我的例子中,我有几个字段可以从用户界面编辑(由管理员用户在应用程序中).因此,我正在寻找通过选项访问器更新这些值的理想方法.

asp.net-core-mvc asp.net-core

24
推荐指数
4
解决办法
1万
查看次数

如何从配置动态传递端点详细信息?

我按照文章将 WCF 服务包含到我的 ASP.NET 核心应用程序中。

查看reference.cs 中的以下行,似乎默认端点配置是在reference.cs 中硬编码的。

return new System.ServiceModel.EndpointAddress("http://localhost:49945/SimpleService.svc");
Run Code Online (Sandbox Code Playgroud)

这就是我如何在 asp.net 核心控制器中创建我的客户端 -

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:49945/SimpleService.svc");
            wcfClient = new SimpleServiceClient(basicHttpBinding, endpointAddress);
Run Code Online (Sandbox Code Playgroud)

所以我的问题是——

  1. 我应该在哪里维护端点详细信息,以便在部署期间可以轻松配置?

  2. 如何从配置文件 (appsetting.json)动态传递端点详细信息(地址和绑定)?

生成的 Reference.cs 文件如下所示 -

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     //
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace SimpleServiceReference …
Run Code Online (Sandbox Code Playgroud)

wcf asp.net-core

3
推荐指数
1
解决办法
8091
查看次数

标签 统计

asp.net-core ×2

asp.net-core-mvc ×1

wcf ×1