Tag: Azure的function

Azurefunction静态隔离

我无法在应用服务计划中找到有关Azurefunction隔离的大量文档。 如果你共享一个静态变量,例如azure色函数调用之间的HttpClient ,我假设读取可以在相同进程或单独进程或单独服务器中运行的可伸缩性建议…这很好,使用Lazy可以帮助线程问题。 但是可以将Azure Functions分开一个工作进程吗? 即我应该隔离静态变量以确保function的隔离? 我收集使用ConcurrentDictionary和函数的密钥是一个很好的方法来帮助解决这个问题,但我没有找到任何讨论隔离的文档。

如何添加对Azure Function C#项目的引用?

在最新的Azure SDK的帮助下,我获得了针对Visual Studio的Azurefunction工具,以便我可以在内部调试我的Azurefunction – 很酷。 我的azure函数需要使用Business对象的代码 从.csx脚本我可以在开始时使用这样的指令引用.dll #r “ServiceBusQueue.Shared.dll” Azurefunction项目中没有“添加引用…”。 我只能添加一个Build依赖项,以便首先构建业务对象dll。 但是当更新DLL代码时,不会将dll输出复制到我的azure函数目录的bin中。 在Web上发布是正确的这是为了在本地调试会话中使用最新的业务对象代码。 由于Azurefunction项目中没有Prebuild事件的选项卡,我找到的解决方案是在Function App项目中编写Prebuild event .funproj文件 批处理文件: rem %1 is the configuration, debug or release echo %1 mkdir .\ServiceBusQueueTriggerCSharp\bin copy ..\ServiceBusQueue.Shared\bin\%1\*.* .\ServiceBusQueueTriggerCSharp\bin rem DOS subtlety : test than return code is equal or greater than 1 rem : make the compilation to fail if […]

不接受Azurefunction(ILogger或TraceWriter)的上次日志记录参数

将我自己的项目从早期(几个月前)版本的Azure Functions升级到当前版本后,从VS启动时出现以下错误。 GetLoginUrl:Microsoft.Azure.WebJobs.Host:错误索引方法’Login.GetLoginUrl’。 Microsoft.Azure.WebJobs.Host:无法将参数’log’绑定到类型ILogger。 确保绑定支持参数Type。 如果您正在使用绑定扩展(例如ServiceBus,Timers等),请确保您已在启动代码中调用扩展的注册方法(例如config.UseServiceBus(),config.UseTimers()等)。 之前,我曾经将TraceWriter log作为我方法的最后一个参数,但后来我发现我应该使用ILogger 。 在我做出改变之前,我得到了与上面相同的错误。 ILogger似乎映射到程序集Microsoft.Extensions.Logging.Abstractions 。 也许这就是为什么它不被认可? 应该使用哪种ILogger ? 这是方法签名。 [FunctionName(“GetLoginUrl”)] public static HttpResponseMessage GetLoginUrl( [HttpTrigger(AuthorizationLevel.Anonymous, “get”, Route = null)]HttpRequestMessage req, ILogger log) 我没有尝试将此部署到Azure。 不幸的是,创建一个全新的Functions项目并没有帮助,因为没有.CS文件可以查找以纠正这个问题。

如何使用Azure Functions删除blob?

我正在创建一个Azure函数,该函数在图像上载或添加到特定Azure存储时触发,并执行以下操作:1。)调整图像大小2.)将图像放入正确的目录(使用输出绑定)3。)删除处理后添加到Azure存储的原始Blob映像。 我完成了流程中的步骤1和步骤2,但是我发现很少有关于删除blob或API的文档,这些文档将公开Azure存储的方法。 (使用C#) 这是示例代码: #r “System.Drawing” using System; using ImageResizer; using System.Drawing; using System.Drawing.Imaging; public static void Run(Stream inputImage, string imageName, Stream resizedImage, TraceWriter log) { // Log the file name and size log.Info($”C# Blob trigger function Processed blob\n Name:{imageName} \n Size: {inputImage.Length} Bytes”); // Manipulate the image var settings = new ImageResizer.ResizeSettings { MaxWidth […]

执行测试时出错,如果使用CreateResponse扩展方法返回Azure Function HttpResonseMessage

我的Azurefunction代码如下所示 public static class MyHttpTriggerFunction { public static async Task Run([HttpTrigger(AuthorizationLevel.Function, “get”, “post”, Route = null)]HttpRequestMessage req, TraceWriter log) { // some business logic if (valid) { return req.CreateResponse(HttpStatusCode.OK, true); } else { return req.CreateResponse(HttpStatusCode.BadRequest, “some error message”); } } } 在我的测试项目中,我正在阅读如下结果: var result = await MyHttpTriggerFunction.Run(req, log).ConfigureAwait(false); 执行该函数后,当它尝试在结果变量中返回响应时,测试方法失败并出现exception。 ** System.InvalidOperationException:请求没有关联的配置对象,或者提供的配置为null。 ** 我确保测试项目具有相同的System.Net.Http.HttpRequestMessageExtension dll。 如果我更改function代码不使用CreateResponse扩展方法(此扩展方法来自VS […]

Newtonsoft.Json引用抱怨Azurefunction

我正在运行一个名为SmsWebhook的Azure Functions。 它调用外部程序AzureFunctionsSample.Services.dll的方法AzureFunctionsSample.Services.dll ,该方法引用了Newtonsoft.Json 8.0.3 我的Run.csx的详细信息如下: #r “AzureFunctionsSample.Services.dll” using System.Net; using AzureFunctionsSample.Services public static async Task Run(HttpRequestMessage req, TraceWriter log) { … } 在上面的Run()方法中,我创建了一个实例并在实例中调用了一个方法。 但是,每当我调用该方法时,都会收到以下错误: 2016-05-19T13:41:45 Welcome, you are now connected to log-streaming service. 2016-05-19T13:41:46.878 Function started (Id=64fccf0c-d0ef-45ef-ac1c-7736adc94566) 2016-05-19T13:41:46.878 C# HTTP trigger function processed a request. RequestUri=https://ase-dev-fn-demo.azurewebsites.net/api/smswebhook 2016-05-19T13:41:46.878 Function completed (Failure, Id=64fccf0c-d0ef-45ef-ac1c-7736adc94566) 2016-05-19T13:41:46.894 Exception while […]

由Microsoft.NET.Sdk.Functions引起的版本冲突

我有一个项目引用2个软件包的问题,​​然后引用Newtonsoft.Json,但两个版本都不同。 我正在使用Refit和Microsoft.NET.Sdk.Functions的nuget包。 当我尝试构建解决方案时,我收到以下错误: C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. \r C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) \r C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json […]

如何将Azure函数的入口点放在.NET DLL中?

Azure Functions示例说明了如何将进程入口点放在C#脚本文件.csx 。 但是,如何使用常规C#库(DLL)来实现此行为? 我可以让Kudu首先编译库,就像为Webapp做的那样吗?

如何通过POST将参数传递给Azure函数?

我正在尝试使用简单的Azurefunction来了解它。 将有3个function: 1用于将行插入数据库表的函数。 该表将包含当前日期和用户键入并由GET传递的字符串参数。 1function类似于前一个,但通过POST传递参数。 1函数读取表并显示其内容。 我已经能够完成第一个和第三个。 但我不能通过POST传递参数。 我找了一些例子,但我不能成功地运行它们。 客户端应用程序是Windows窗体。 谁能告诉我一个例子,如何通过POST将参数传递给函数以及如何阅读它们? 提前致谢 编辑: 这是通过GET传递参数的代码(这很好): private void button2_Click(object sender, EventArgs e) { string cadena = lsql1.Text + “?notas=” + tNotas.Text; try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(cadena); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); if (res.StatusCode == HttpStatusCode.OK) { MessageBox.Show(“Grabado”); } else { MessageBox.Show(res.StatusDescription); } }catch (WebException ex) { using […]

使用Azurefunction损坏已resize的图像

我有一个带有一个输入和两个输出的azurefunction应用程序。 在这种情况下,每当图像上传到容器:原件时,将触发function应用程序,这将生成两个缩略图图像。 码: using System; using System.Text; using System.Net.Http; using System.Net.Http.Headers; using System.Collections.Generic; public static void Run(Stream myBlob,string blobname, string blobextension, Stream outputBlobsm,Stream outputBlobmd, TraceWriter log) { bool smartCropping = true; log.Info($”C# Blob trigger function Processed blob\n Name:{blobname} \n Extension: {blobextension} extension”); var sizesm = imageDimensionsTable[ImageSize.Small]; log.Info($”C# Blob \n width:{sizesm.Item1} \n height: {sizesm.Item2}”); ResizeImage(sizesm.Item1, sizesm.Item2,smartCropping,myBlob, […]