我可以看到 Azure Function 目录中添加了两个 json 文件(host.json 和 local.settings.json)。
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
Run Code Online (Sandbox Code Playgroud)
拥有这两个json文件的目的是什么?
我们将IdentityServer4与.NET Core Web应用程序一起使用(“ http://docs.identityserver.io/en/release/quickstarts/0_overview.html ”)。我们已替换AddDeveloperSigningCredential为AddSigningCredential(CreateSigningCredential())。由于我们不能AddDeveloperSigningCredential用于生产环境,因为生产中需要用一些持久的密钥材料代替。我们是IdentityServer4的新手,我们的问题是,以下方法可以在生产环境中创建签名凭证吗?还是我们需要对此进行一些更改?
这是我们的startup.cs文件:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
//connection string
string connectionString = Configuration.GetConnectionString("IdentityServer");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer().AddDeveloperSigningCredential
.AddSigningCredential(CreateSigningCredential())
// this adds the config data from DB (clients, resources)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
}) // this adds the operational data from DB (codes, tokens, consents)
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
// this enables automatic token cleanup. …Run Code Online (Sandbox Code Playgroud) 我正在使用 Amadeus 提供的 WSDL 文件 (wsdl.zip)。当尝试使用下面的代码调用服务方法时,它抛出了一个 System.PlatformNotSupportedException 说“ Compiling JScript/CSharp scripts is not supported”
public async Task<Fare_MasterPricerTravelBoardSearchResponse> SearchFlight(Session session,
Fare_MasterPricerTravelBoardSearch searchData)
{
var _client = new AmadeusWebServicesPTClient();
var result = await _client.Fare_MasterPricerTravelBoardSearchAsync(session, searchData);
return result;
}
Run Code Online (Sandbox Code Playgroud)
这真的是工具还不支持的东西吗?
堆栈跟踪:
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.ServiceModel.Description.XmlSerializerHelper.FromMappingsViaReflection(XmlMapping[] mappings, Type type)
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GenerateSerializers()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GetSerializer(Int32 handle)
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerStub.GetSerializer()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.MessageInfo.get_HeaderSerializer()
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.AddHeadersToMessage(Message message, MessageDescription messageDescription, Object[] parameters, Boolean …Run Code Online (Sandbox Code Playgroud) 我将使用 Azure Function App 的密钥保管库。
我正在使用.NET SDK。
例子:
string keyVaultUrl = configuration["KeyVaultSettings:Url"];
TokenCredential credential = new DefaultAzureCredential();
#if DEBUG
credential = new ClientSecretCredential(configuration["AZURE_TENANT_ID"],
configuration["AZURE_CLIENT_ID"],
configuration["AZURE_CLIENT_SECRET"]);
#endif
var secretClient = new SecretClient(new Uri(keyVaultUrl), credential);
Run Code Online (Sandbox Code Playgroud)
要在本地调试我需要
tenant_id、client_id 和 client_secret。
我怎样才能得到这个?
我正在使用 Azure Function(v3),我可以在startup.cs 中使用 IWebJobsStartup 和 FunctionsStartup 注册依赖项。
但我们应该使用哪一个呢?
使用 IWebJobsStartup 注册依赖项
[assembly: WebJobsStartup(typeof(Startup))]
namespace Notifications.Receiver
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
builder.Services.AddTransient<IEventValidator, EventValidator>();
builder.Services.AddTransient<IEventReceiverHandler, EventReceiverHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto,InvoiceMessageEvent>, InvoiceMessageEventHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto, InvoiceFileEvent>, InvoiceFileEventHandler>();
builder.Services.AddSingleton<IMessageBusFactory, AzureServiceBusFactory>();
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也可以使用 FunctionsStartup 注册相同的依赖项
[assembly: FunctionsStartup(typeof(Startup))]
namespace Notifications.Receiver
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddTransient<IEventValidator, EventValidator>();
builder.Services.AddTransient<IEventReceiverHandler, EventReceiverHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto,InvoiceMessageEvent>, InvoiceMessageEventHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto, InvoiceFileEvent>, InvoiceFileEventHandler>();
builder.Services.AddSingleton<IMessageBusFactory, AzureServiceBusFactory>(); …Run Code Online (Sandbox Code Playgroud) 我们使用的是 Identity Server4,默认时间是访问令牌过期时间是 3600 秒。我们可以设置它不过期吗?
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ClientCredentials,
// secret for authentication
ClientSecrets =
{
new Secret("secret".Sha256())
},
// scopes that client has access to
AllowedScopes = { "api1" },
AccessTokenLifetime=3600
}
};
Run Code Online (Sandbox Code Playgroud) 目前我们正在使用 Blob 触发器 Azure Functions 将 json 数据移动到 Cosmos DB。我们计划用 Azure 数据工厂 (ADF) 管道替换 Azure Functions。我是 Azure 数据工厂(ADF)的新手,所以不确定,Azure 数据工厂(ADF)管道是否是更好的选择?
我们使用 log4net 库和 .NET Core 将日志写入文件。但是,在执行应用程序“log4net:错误的ConfigureFromXml 使用 null 'element' 参数调用”时,我们收到此错误。这是我们的 Program.cs 文件:
public class Program
{
public static void Main(string[] args)
{
XmlDocument log4netConfig = new XmlDocument();
log4netConfig.Load(File.OpenRead("log4net.config"));
var repo = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
log4net.Config.XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
Run Code Online (Sandbox Code Playgroud)
这是Startup.cs文件中的Configure方法:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
loggerFactory.AddConsole(LogLevel.Trace);
loggerFactory.AddLog4Net();
app.UseIdentityServer();
}
Run Code Online (Sandbox Code Playgroud)
这是 log4net.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, …Run Code Online (Sandbox Code Playgroud) 我正在使用下面的存储过程从 cosmos db 集合中删除项目。
function bulkDeleteStoredProcedure(query) {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
var responseBody = {
deleted: 0,
continuation: true
};
// Validate input.
if (!query) throw new Error("The query is undefined or null.");
tryQueryAndDelete();
// Recursively runs the query w/ support for continuation tokens.
// Calls tryDelete(documents) as soon as the query returns documents.
function tryQueryAndDelete(continuation) {
var requestOptions = {continuation: continuation};
var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, function (err, retrievedDocs, responseOptions) …Run Code Online (Sandbox Code Playgroud)