none
Outlook 64bit (VSTO) GetAsync call RRS feed

  • Question

  • Hi,

    i try this from Outlook-AddIn:

    _httpClient = new HttpClient();
    
    var credential = new NetworkCredential(user, password);
    
    string usernamePassword = credential.UserName + ":" + credential.Password;
    
    string authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(usernamePassword));
    
    _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo);
    
    await _httpClient.GetAsync(new Uri(url.ToString()));

    The request is being processed on the server and completed. However, the will not come back to Outlook.

    I have created a addin with VSTO. from Word or Excel works the same request. Have already tried with TimeOut.
    No effect, Outlook stops. Other security settings checked, no effect.

    Ideas?

    Thank you

    greeting

    ATozlu
                                             

    Tuesday, November 11, 2014 1:50 PM

Answers

All replies

  • Hello,

    Try to run another thread explicitly. Outlook uses the single threaded apartment model, so the UI thread should be free.

    Does your http request work as expected in that case?

    Tuesday, November 11, 2014 1:59 PM
  • Thanks Eugene,

    have you an example for me?

    This is my Code:

            public async Task<bool> InitializeHttpClient(string user, string password, string host, string port)
            {
                try
                {
    
                    var url = new StringBuilder();
                    url.Append("http://");
                    url.Append(host);
                    url.Append(":");
                    url.Append(port);
                    url.Append(ServiceRoot);
                    url.Append(ServiceInfo);
    
                    _httpClient = new HttpClient();
    
                    var credential = new NetworkCredential(user, password);
                    string usernamePassword = credential.UserName + ":" + credential.Password;
                    string authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(usernamePassword));
    
                    _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authInfo);
    
                    await _httpClient.GetAsync(new Uri(url.ToString()));
    
                    _host = host;
                    _port = port;
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }            
            }

    • Edited by nashieli Tuesday, November 11, 2014 2:02 PM
    Tuesday, November 11, 2014 2:01 PM
  • Try to reproduce the issue with a secondary thread without using async operators. You can use the Start method of the Thread class instead.

    The current forum is for Outlook specific questions. I'd suggest asking thread specific questions on the "Visual C#" or "Visual Basic" forums.

    Tuesday, November 11, 2014 3:04 PM
  • Hi Eugene,

    thank's. It's works..

    • Marked as answer by nashieli Tuesday, November 18, 2014 10:24 AM
    Tuesday, November 18, 2014 10:24 AM