none
Initializing EWS Service prevents postback RRS feed

  • Question

  • I am developing a plugin which utilises EWS for an existing product and I have discovered that initializing the service prevents me from making a postback to my ASPX pages.

    I traced this back to the Initialization call for EWS through trial and error, commenting and uncommenting sections until postback was successful.

    Why is this happening?

    Example:

    AjaxHandler.aspx.cs

            public void Test()
            {
                Response.Clear();
                Response.Write("Test");
                Response.Flush();
                Response.End();
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
                   if (Request.Params["Request"].Equals("LoadEWS"), StringComparison.InvariantCulture))
                   {
                    // < --- Irrelevant code omitted --- >
                    SoapClient.LoadExchangeWebServiceData(Session, email, password, version);
                    Test();
                    }
             }
    SoapClient.cs

     public static void LoadExchangeWebServiceData(HttpSessionState Session, string email, string password, string version)
            {
                try
                {
                    Functions functions = new Functions(email, password, version);
                }
                catch (Exception)
                {
                    throw;
                }
            }
    
        public class Functions
        {
            private ExchangeService _service;
    
            public Functions(string emailAddress, string password, string exchangeVersion)
            {
                try
                {
                    #region Troubleshooting
                    // Any initialization of ExchangeService prevents postback using Response.Write() as called in `Test()` method
                    // If this next line is commented out postback works as expected
                    _service = new ExchangeService(ExchangeVersion.Exchange2010);
                    //_service.AutodiscoverUrl(emailAddress);
                    //_service.Credentials = new NetworkCredential(emailAddress, password);
                    //_service.AutodiscoverUrl(emailAddress);
                    #endregion
                    
                    // No issues with postback populating below object
                    UserData userData = new UserData();
                    userData.SetEmailAddress(emailAddress);
                    userData.SetPassword(password);
                    userData.SetExchangeVersion(exchangeVersion);
                    
                    // What I use when I utilize this class from elsewhere. Commented out as part of troubleshooting
                    //_service = Service.ConnectToService(userData, new TraceListener());
                    //_service = Service.ConnectToService(userData);
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to connect to Exchange Service", ex);
                }
            }
    
    
    Displaying Response (ASPX Page)

    function ajaxResponse()
    {
        if (xmlhttp.readyState == 4)
        {
            alert("ResponseText: " + xmlhttp.responseText.toString());
        }
    }

    With EWS service initialization commented out, the alert is posted on screen. With any form of the service initialization enabled I see no alert box.

    • Edited by Alexabix Tuesday, April 23, 2013 3:50 PM
    Tuesday, April 23, 2013 3:36 PM