Azure功能 - System.Net.Http

时间:2017-04-08 18:40:49

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

使用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包的各种组合 - 但没有运气。

有谁知道我应该使用哪些软件包才能使其正常工作?

2 个答案:

答案 0 :(得分:1)

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

我建议您添加try以将它们直接添加到预编译项目中。

以下是一些具有http触发器的预编译函数示例(12)。

答案 1 :(得分:1)

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

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