none
Unable to invoke controller in an Outlook addin RRS feed

  • Question

  • Hi Team, i am creating an addin for outlook using VS2015.

    I have created the default addin from VS2015 and was able to deploy it on my O365 account. Now i am trying to create a controller in the addin which will have a business logic.

    Below is what i did

    1. Created a controller class and have below method in it

            [HttpPost()]
            [ActionName("SendFeedback")]
            public FeedbackResponse SendFeedback(FeedbackRequest request)
            {
                try
                {
                    return new FeedbackResponse();
                }

                catch (Exception)
                {
                    return new FeedbackResponse()
                    {
                        Status = "Sorry, your feedback could not be sent",
                        Message = "You may try emailing it directly to the support team."
                    };
                }
            }
            public class FeedbackRequest
            {
                public int? Rating { get; set; }
                public string Feedback { get; set; }
            }

            public class FeedbackResponse
            {
                public string Status { get; set; }
                public string Message { get; set; }
            }

    2. Global.asax has the below

            protected void Application_Start(object sender, EventArgs e)
            {
                RouteTable.Routes.MapHttpRoute
                    (
                        name: "DefaultApi",
                        routeTemplate: "api/{controller}/{action}/{id}",
                        defaults: new { id = RouteParameter.Optional }
                    );
            }

    3. Now i am calling this from java script client file as below -

          var dataToPassToService = {
              Feedback: 'This is a average feedback',
              Rating: 'This is a average rating'
          };

          $.ajax({
              url: '../../api/AddressValidation/SendFeedback',
              type: 'POST',
              data: JSON.stringify(dataToPassToService),
              contentType: 'application/json;charset=utf-8'
          }).done(function (data) {
              // placeholder
          }).fail(function (status) {
              // placeholder
          }).always(function () {
              // placeholder
          });

    But the controller class is not hit. Am i missing something or do i need to do any more changes?

    Appreciate your support.

    Thanks

    Sunday, October 9, 2016 12:06 PM

Answers

  • Hi Nakul,

    How did you check whether the controller whether is hit or not? I suggest you add breakpoints at SendFeedback method and $.ajax request. If $.ajax method is not hit, it seems you did not add the method to the correct button, something like below:

    /// <reference path="../App.js" />
    
    (function () {
        "use strict";
        // The initialize function must be run each time a new page is loaded
        Office.initialize = function (reason) {
            $(document).ready(function () {
                app.initialize();
                $('#send').click(sendFeedback);
            });
        };
    
        function sendFeedback() {
            $('.disable-while-sending').prop('disabled', true);
            // Magic happens
        }
    })();
    

    If $.ajax method is hit, I suggest you try Fiddler to check the real request url.

    I suggest you refer the link below for detailed steps to create a web service for an app for Office, and you could try download the worked demo to check the differences.
    #Create a web service for an app for Office using the ASP.NET Web API
    https://blogs.msdn.microsoft.com/officeapps/2013/06/10/create-a-web-service-for-an-app-for-office-using-the-asp-net-web-api/

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by Nakul Virmani Tuesday, October 11, 2016 10:41 AM
    Monday, October 10, 2016 1:37 AM

All replies

  • Hi Nakul,

    How did you check whether the controller whether is hit or not? I suggest you add breakpoints at SendFeedback method and $.ajax request. If $.ajax method is not hit, it seems you did not add the method to the correct button, something like below:

    /// <reference path="../App.js" />
    
    (function () {
        "use strict";
        // The initialize function must be run each time a new page is loaded
        Office.initialize = function (reason) {
            $(document).ready(function () {
                app.initialize();
                $('#send').click(sendFeedback);
            });
        };
    
        function sendFeedback() {
            $('.disable-while-sending').prop('disabled', true);
            // Magic happens
        }
    })();
    

    If $.ajax method is hit, I suggest you try Fiddler to check the real request url.

    I suggest you refer the link below for detailed steps to create a web service for an app for Office, and you could try download the worked demo to check the differences.
    #Create a web service for an app for Office using the ASP.NET Web API
    https://blogs.msdn.microsoft.com/officeapps/2013/06/10/create-a-web-service-for-an-app-for-office-using-the-asp-net-web-api/

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by Nakul Virmani Tuesday, October 11, 2016 10:41 AM
    Monday, October 10, 2016 1:37 AM
  • Thanks Edward.

    The problem was that DefaultApi was getting added twice in Routes due to which an exception was thrown. Fixed it by removing the duplicate entry. Now the controller is getting invoked & I am able to perform the business logic.

    Tuesday, October 11, 2016 10:41 AM