【问题标题】:Azure Functions - System.Net.HttpAzure 函数 - System.Net.Http
【发布时间】:2017-04-08 18:40:49
【问题描述】:

在使用 Azure Functions 时,我在使用 System.Net.Http 库时遇到了很多麻烦。如果我在门户中创建一个全新的 httptrigger 函数,它可以正常工作。但是,我想使用我自己的precompiled assembly。当我这样做时,我会遇到各种各样的问题。

我看到的一个症状是传入的HttpRequestMessage 没有详细信息。 RequestUri 为空,加上任何其他属性 - 例如。标头等。请注意,该参数不为空 - 它似乎没有填充任何内容。

另一个症状是,当它尝试调用GetQueryNameValuePairs 时,它会说:

Exception while executing function: Functions.WebHookSync. mscorlib: Exception has been thrown by the target of an invocation. MyFunctionName.Functions: Method not found: 'System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<System.String,System.String>> System.Net.Http.HttpRequestMessageExtensions.GetQueryNameValuePairs(System.Net.Http.HttpRequestMessage)'.

以下是我的 .csproj 文件的内容:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyOtherAssembly\MyOtherAssembly.csproj" />
  </ItemGroup>
</Project>

Microsoft.AspNet.WebApi.Core nuget 包包含 system.net.http 库。我尝试了与此相关的不同 nuget 包的各种组合 - 但没有运气。

有谁知道我应该使用什么包来让它工作?

【问题讨论】:

    标签: c# .net azure nuget azure-functions


    【解决方案1】:

    我在 System.Net.Http 中遇到了 MissingMethodExceptions 问题。对我有用的是以下参考:

    <package id="System.Net.Http" version="4.0.0" targetFramework="net461" />
    

    【讨论】:

    • 这似乎工作了。虽然不幸的是,这不包括 GetQueryNameValuePairs 方法,所以我只是使用正则表达式来解析查询字符串。还不得不将我所有的其他库降级到 46(从 .net 核心),因为那里出现了链依赖错误。希望 Azure Functions 能尽快支持 .NET Core (github.com/Azure/Azure-Functions/issues/98)。
    【解决方案2】:

    这是函数运行时中的System.Net.Http references

    我建议你添加尝试将它们直接添加到你的预编译项目中。

    这里有几个预编译的函数示例,它们也可以尝试使用 http 触发器 (1,2)。

    【讨论】:

      猜你喜欢
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      相关资源
      最近更新 更多