2017-04-08 57 views
2

使用Azure函數時,我遇到了很多System.Net.Http庫問題。如果我在門戶中創建一個全新的httptrigger函數,它工作正常。但是,我想用我自己的precompiled assembly。當我這樣做時,我會遇到各種各樣的問題。Azure函數 - System.Net.Http

我看到的一個症狀是傳入的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軟件包的各種組合 - 但沒有運氣。

有誰知道我應該用什麼軟件包來實現這個功能?

回答

1

我在System.Net.Http中遇到MissingMethodExceptions問題。對我有效的是以下參考:

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

這似乎現在工作。不幸的是,這不包括GetQueryNameValuePairs方法,所以我只是使用正則表達式來分析查詢字符串。也不得不將所有其他庫降級到46(來自.net核心),因爲那裏成爲鏈依賴性錯誤。希望Azure函數能很快支持.NET Core(https://github.com/Azure/Azure-Functions/issues/98)。 – Dan

1

以下是函數運行時的System.Net.Http references

我建議你添加嘗試將它們直接添加到你的預編譯項目。

這裏有幾個預編譯的函數樣本,它們還有http觸發器可供嘗試(12)。