问题描述
如果不使用 C# 实现(不是 CSX)中的 [BlobAttribute],我无法将 blob 类型的输入参数绑定到字符串/TextReader.
I'm not able to bind an input parameter of type blob to either string/TextReader without using the [BlobAttribute] in a C# implementation (not CSX).
我得到的错误是:
Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.Harvester'.
Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'configReader' to type
TextReader. Make sure the parameter Type is supported by the binding. If
you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure
you've called the registration method for the extension(s) in your startup
code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
function.config:
function.config:
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */5 * * * *",
"useMonitor": true,
"runOnStartup": false,
"direction": "in",
"name": "myTimer"
},
{
"type": "blob",
"name": "configReader",
"path": "secured/app.config.json",
"connection": "XXX",
"direction": "in"
}
],
函数签名(不绑定configReader):
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
TextReader configReader)
尽管如此(BINDING configReader:
This would work though (BINDING configReader:
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
[Blob("secured/app.config.json", FileAccess.Read)]TextReader configReader)
关于如何在不指定 BlobAttribute 中的 blob 路径的情况下使其工作的任何想法.理想情况下,我会将 Blob 配置保留在代码之外,这样我的函数就会变得更加可移植.
Any idea on how to get it working without specifying the blob path in BlobAttribute. I'd ideally keep the Blob config outside of the code, that way my function would become more portable.
推荐答案
问题出在最新的运行时支持 function.json 中的新属性 (代码>configurationSource)
The issue turned out to be with the latest runtime supporting a new property (configurationSource) in function.json
这告诉运行时使用 config(即 function.json)或 C# 属性进行函数配置.
This tells the runtime to use either config (which is function.json) or C# attributes for function config.
基本上允许您像这样定义您的函数
essentially allowing you to either define your function like this
现在您可以将函数定义为
Now you can either define your function as
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger]TimerInfo myTimer,
TraceWriter log,
TextReader configReader)
{
}
还有一个看起来像这样的 function.json
along with a function.json that looks like this
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "config",
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */5 * * * *",
"useMonitor": true,
"runOnStartup": false,
"direction": "in",
"name": "myTimer"
},
{
"type": "blob",
"name": "configReader",
"path": "secured/app.config.json",
"connection": "XXX",
"direction": "in"
}
],
"disabled": false,
"scriptFile": "...",
"entryPoint": "..."
}
或者像这样
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
[Blob("secured/app.config.json", FileAccess.Read)]TextReader configReader)
{
}
像这样更简单的配置
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"name": "myTimer"
},
],
"scriptFile": "...",
"entryPoint": "..."
}
注意两个示例中 configurationSource 的值.
note the value of configurationSource in both examples.
Visual Studio 2017 的工具默认执行后者.如果您想更改您的 function.json 以包含您的所有配置并更改 configurationSource 您将需要在您的项目中包含该文件并将其标记为始终复制.这个 GIF 展示了如何做到这一点.
The tooling for Visual Studio 2017 does the latter by default. If you wanna change your function.json to include all your config and change the configurationSource you will need to include the file in your project and mark it as always copy. This GIF shows how to do that.
这篇关于Azure 函数 blob 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)