使用Azure Functions,我可以在C#函数中引用和使用NuGet包吗?
c# azure nuget-package azure-web-app-service azure-functions
我有一些类库,我在ASP.NET Web API应用程序中使用它来处理我的所有后端内容,例如对多个数据库(如Azure SQL数据库,Cosmos DB等)的CRUD操作.
我不想重新发明轮子,并且能够在我在Visual Studio 2017中创建的新Azure功能中使用它们.我的所有存储库方法都使用接口.那么,我将如何在我的新Azure功能中实现依赖注入?
我没有看到对DI的任何支持,但我有点困惑.似乎Azure Functions基于与WebJobs相同的SDK,我认为去年微软已经开始在WebJobs中支持DI - 我当然知道,因为我使用Ninject实现了它.
有没有解决方法,以便我可以在我的新Azure功能项目中使用我现有的库?
我正在尝试从 AWS Lambda 中运行一个爬虫蜘蛛。这是我当前脚本的样子,它正在抓取测试数据。
import boto3
import scrapy
from scrapy.crawler import CrawlerProcess
s3 = boto3.client('s3')
BUCKET = 'sample-bucket'
class BookSpider(scrapy.Spider):
name = 'bookspider'
start_urls = [
'http://books.toscrape.com/'
]
def parse(self, response):
for link in response.xpath('//article[@class="product_pod"]/div/a/@href').extract():
yield response.follow(link, callback=self.parse_detail)
next_page = response.xpath('//li[@class="next"]/a/@href').extract_first()
if next_page:
yield response.follow(next_page, callback=self.parse)
def parse_detail(self, response):
title = response.xpath('//div[contains(@class, "product_main")]/h1/text()').extract_first()
price = response.xpath('//div[contains(@class, "product_main")]/'
'p[@class="price_color"]/text()').extract_first()
availability = response.xpath('//div[contains(@class, "product_main")]/'
'p[contains(@class, "availability")]/text()').extract()
availability = ''.join(availability).strip()
upc = response.xpath('//th[contains(text(), "UPC")]/'
'following-sibling::td/text()').extract_first()
yield {
'title': title,
'price': price,
'availability': availability, …Run Code Online (Sandbox Code Playgroud) 我有一个带有服务总线触发器的Azure功能:
public static async Task Run([ServiceBusTrigger(
"%inputTopicName%",
"%subscriptionName%",
AccessRights.Manage,
Connection = "connection")]string mySbMsg)
Run Code Online (Sandbox Code Playgroud)
在99.9%的调用中,触发器成功解析为Azure Service Bus上的订阅.但有时,我在日志中看到以下错误:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: UptimeChecker ---> System.ArgumentException: The argument connectionString is null or white space.
Parameter name: connectionString
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.FunctionInvocationFilterInvoker.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.d__23.MoveNext()
--- …Run Code Online (Sandbox Code Playgroud) 我有一个托管在 Azure 应用服务上的 ASP .Net Core 3.0 Web API。我试图找出为什么它在控制器操作方法之一中抛出 500 内部服务器错误。我已经设置了 Application Insights,并且可以在 Azure 门户上的“失败”页面上看到有多个 500 异常。但是,我看不到它们的堆栈跟踪。我需要做什么才能在 Application Insights 或 Azure Monitor 中打开堆栈跟踪报告。PS 即使我的 API 在 .Net Core 2.2 上,它也没有显示堆栈跟踪,因此它不是 .Net Core 3.0 的东西。
这是一些屏幕截图:
azure azure-monitoring asp.net-core-mvc azure-application-insights
基本上我需要选择一个,以便我可以快速熟悉它,然后根据我的需要进行自定义.
我是.NET开发人员,也知道经典的ASP.但我认为理解PHP对我来说不是问题,也认为它不会那么困难.
你想推荐我什么?
更新: -
抱歉我迟到了这个信息.现在我不知道我将做什么样的定制.但我相信我会继续我有自己的要求,需要定制.所以我不想处于这样的情况,我将不得不说"我正在使用的这个引擎不允许我更改XYZ,或者我在这个博客软件中进行XYZ更改会很困难,所以我们要迁移别的."
我更喜欢简短的学习曲线.
我正在创建一个Azure函数,它将接收一个POSTed文件并对其进行处理.我有基础设置,我可以成功发布一个小文件.每当我发布一个大文件时,我都会收到以下错误消息.
A ScriptHost error has occurred
Exception while executing function: Functions.HttpTriggerCSharp. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'request'. System.ServiceModel: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
Exception while executing function: Functions.HttpTriggerCSharp
Executed: 'Functions.HttpTriggerCSharp' (Failed)
Function had errors. See Azure …Run Code Online (Sandbox Code Playgroud) 我想将 Azure blob 下载到流中,然后将流转换为图像以调整大小,然后使用新名称将新图像上传到 Azure blob。现在我可以调整图像大小并上传流,但我无法将具有新名称的流上传到 Azure。
这是我的代码:
Stream stream = blockBlob.OpenRead();
Image newImage;
Bitmap image = new Bitmap(stream);
newImage = new Bitmap(image, 20, 20);
var ms = new MemoryStream();
newImage.Save(ms, ImageFormat.Png);
ms.Position = 0;
blockBlob.UploadFromStream(ms);
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Azure 函数从 blob 存储返回文件。就目前情况而言,我已经让它工作了,但是通过将整个 blob 读入内存,然后将其写回,它的工作效率很低。这适用于小文件,但一旦它们变得足够大,效率就非常低。
如何让我的函数直接返回 blob,而无需将其完全读入内存?
这是我目前正在使用的:
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, Binder binder, TraceWriter log)
{
// parse query parameter
string fileName = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
string binaryName = $"builds/{fileName}";
log.Info($"Fetching {binaryName}");
var attributes = new Attribute[]
{
new BlobAttribute(binaryName, FileAccess.Read),
new StorageAccountAttribute("vendorbuilds")
};
using (var blobStream = await binder.BindAsync<Stream>(attributes))
{
if (blobStream == null)
{
return req.CreateResponse(HttpStatusCode.NotFound);
}
using(var memoryStream = new MemoryStream())
{
blobStream.CopyTo(memoryStream);
var response = …Run Code Online (Sandbox Code Playgroud) 我有一个要从Azure Functions v1移植到v2的函数,并且作为其中一部分,我遇到了更新单元测试(创建存根的HttpRequestMessage)的问题。这是针对.NET Framework 4.7的在Function v1上运行的代码
public class FunctionExample
{
[FunctionName(nameof(SomeFunction))]
public static async Task<HttpResponseMessage> SomeFunction
(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "SomeFunction")]
HttpRequestMessage request
)
{
var body = await request.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(body))
{
return request.CreateResponse(HttpStatusCode.BadRequest, "Bad job");
}
else
{
return request.CreateResponse(HttpStatusCode.OK, "Good job");
}
}
}
Run Code Online (Sandbox Code Playgroud)
还有我的测试代码
public class FunctionExampleTests
{
[Test]
public async Task TestSomeFunction()
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("http://localhost/"),
Content = new StringContent("", Encoding.UTF8, "application/json")
};
request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取 html 页面中的元素,我使用 document.elementFromPoint(x,y) 来检测输入元素;当没有 iframe 时它工作正常。但是在 iframes 中它在这段代码中不起作用
html如下
我错过了什么吗?
<html>
...
<div>
<div>
<iframe src="some source"..>
<html>
..
<form>
<fieldset>
<input>
Run Code Online (Sandbox Code Playgroud)
谢谢
HAProxy 中 Nginx pass_proxy 的等价物是什么
location /{
proxy_pass https://WebApplication.azurewebsites.net;
}
Run Code Online (Sandbox Code Playgroud)
我尝试测试此配置,但是当我指向具有以下配置的任何后端服务器时收到 404,而不在 root 上使用 ACL,例如使用自签名证书
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log /dev/log local0
log /dev/log local1 notice
user haproxy
group haproxy
maxconn 16000
stats socket /var/lib/haproxy/stats level admin
tune.bufsize 32768
tune.maxrewrite 1024
tune.ssl.default-dh-param 2048
daemon
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout …Run Code Online (Sandbox Code Playgroud)