2014-01-31 2 views
6

Справочная информация. Я установил учетную запись службы для своего проекта в консоли разработчика Google и используя адрес электронной почты службы, сертификат и секретный пароль и следуя примеру, укажите в GoogleAPisSample Plus.ServiceAccount , Фрагмент ниже является частью моего приложения службы Windows:Использование сервиса GoogleApisClient ServiceAccountCredential RequestAccessTokenAsync throws Exception

var List<string> Scopes = new List<string> { "https://www.googleapis.com/auth/analytics.readonly" }; 

var credential = new ServiceAccountCredential(
        new ServiceAccountCredential.Initializer(ServiceAccountEmail) 
        { 
         Scopes = Scopes 
        }.FromCertificate(certificate)); 


       if(credential.RequestAccessTokenAsync(CancellationToken.None).Result) 
       { 

        AuthenticationKey = credential.Token.AccessToken; 
       } 

Когда я установить и запустить эту услугу на моей локальной машине развития он делает штраф credential.RequestAccessTokenAsync и получает маркер доступа и служба осуществляет и делает чтение данных Google Analytics.

Однако при развертывании на нашем QA среде (Window Server 2008 R2 Standard) и запустить снова, следующее исключение брошено, когда credential.RequestAccessTokenAsync называется:

System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'System.Net.HttpStatusCode System.Net.Http.HttpResponseMessage.get_StatusCode()'. 
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) 
    at OurApplication.SchedulerService.GoogleAnalytics.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__b.MoveNext() 
    --- End of inner exception stack trace --- 
    at System.Threading.Tasks.Task`1.get_Result() 
    at OurApplication.SchedulerService.GoogleAnalytics.GADataFetcher.AuthenticateAndAuthorize() 
    at OurApplication.SchedulerService.GoogleAnalytics.GADataFetcher..ctor() 
    at OurApplication.SchedulerService.GoogleAnalytics.GoogleAnalyticsService.GoogleAnalyticsTopPerformances(Int32 sessID, String sessToken) 
---> (Inner Exception #0) System.MissingMethodException: Method not found: 'System.Net.HttpStatusCode System.Net.Http.HttpResponseMessage.get_StatusCode()'. 
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) 
    at Seatwave.SchedulerService.GoogleAnalytics.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__b.MoveNext()<--- 

Я уверен, что я есть последние версии следующих в packages.config:

<package id="Microsoft.Bcl" version="1.1.6" targetFramework="net40" /> 
    <package id="Microsoft.Bcl.Async" version="1.0.165" targetFramework="net40" /> 
    <package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net40" /> 
    <package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net40" /> 

и следующее в app.config:

<dependentAssembly> 
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0" /> 
    </dependentAssembly> 

Итак, мой вопрос, почему он отлично работает на моей машине Dev и выбрасывает это исключение, о котором я упоминал выше, в нашей среде QA (Windows Server 2008 R2 Standard)?

ответ

5

Нашли решение! Это не было связано с API Google Analytics. Это была комбинация из двух вещей:

  1. Установка KB2468871 .Net 4.0 Patch на нашем QA и живых серверов.
  2. Обновление для дальнейшего более новых версий следующих библиотек DLL в app.config:

    <dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.6.6.0" newVersion="2.6.6.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.2.18.0" newVersion="2.2.18.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.2.18.0" newVersion="2.2.18.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0" /> </dependentAssembly> </assemblyBinding>

+0

Установка KB работал для меня, как хорошо (я уже последние версии библиотек DLL или даже более свежую версию) – Benoit74B