Click here to Skip to main content
15,850,545 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Web Api is not returning after action is successfully invoked.

Here is the action I am trying to Invoke
   public class TestController : ApiController{
        // GET api/test
        public string[] Get()
            string[] names = new string[3] {"Matt", "Joanne", "Robert"};
            using (SpeechSynthesizer ss = new SpeechSynthesizer())
                ss.Rate = -2;
                var word = "Test This Two";

                var filePath = HttpContext.Current.Request.MapPath("~/Content/sounds/" + word + ".wav");
            return names;

From the browsers perspective, the page continues to cycle, waiting for a response, after this method has successfully returned the string array.

Does anyone know why this method is not returning results to the browser? Is it possible that an asynchronous thread is still running? I have debugged this method and it is invoked and returns successfully.



This is a test, and I am expecting the results to contain the static array. All I am trying to accomplish is making sure I can use the System.Speech assembly on my hosting environment, but first I am trying to make it work locally.

Update 2

I commented out the using statement and I successfully received the static array as xml in the browser. Therefore, its the System.Speech code that is causing the problems

I did finally received an error message on the browser: An asynchronous module or handler completed while an asynchronous operation was still pending.

This error is odd to me, because according to what I can gathered from MSDN, the SpeechSynthesizer methods I am using are synchronous, which is what I want.
Updated 30-Apr-13 10:23am
Richard C Bishop 30-Apr-13 14:39pm    
How are you capturing the response?
RobNO 30-Apr-13 14:43pm    
I am simply using the direct url in the browser (e.g. http://localhost:61303/api/test), but unfortunately I never receive my response, which is why I am confused because when I debug this method it returns successfully.
Richard C Bishop 30-Apr-13 14:47pm    
If you do not have anything on your page to capture the response, you will never get it. Are you using SOAP to communicate with the API and using the response from that?
RobNO 30-Apr-13 14:50pm    
I am using Web Api which is based around HTTP. I should be seeing the results (the static string array) in XML on the browser.
db7uk 30-Apr-13 14:42pm    
I doubt it. not sure that calling the speech synthesizer is right also... are you expecting this to be heard on the website?

Anyway, what does the response show you in fiddler? what happens if you just return a string value "test" without the array. are you wanting the array to appear or the sound?

1 solution

public string[] Get()
    string[] names = new string[3] { "Matt", "Joanne", "Robert" };
    using (SpeechSynthesizer ss = new SpeechSynthesizer())
        //ss.Rate = -2;
        //var word = "Test This Two";

        //var filePath = HttpContext.Current.Request.MapPath("~/Content/sounds/" + word + ".wav");
    //    //ss.SetOutputToWaveFile(filePath);
        ss.Speak("Hello World");
    //    //ss.SetOutputToNull();
    //    //ss.Dispose();
    return names;

Can't claim to know why but comment out the bold line and this works perfectly, uncomment it and you hear the text, but no response. Something in the synthesiser must be conflicting with the Web API Framework or taking too long to respond. Between this and the comments, I can't be much more help I'm afraid. Personally, I'd look at making the synth call asynchronous.
Share this answer
RobNO 30-Apr-13 16:06pm    
Thanks for all your help! I think your right that there is a conflict with the Web API Framework and System.Speech.

Just speculating but I think the problem is SpeechSynthesizer implicitly kicks off threads (which according to msdn is dose not). The action method returns while the other thread is still continues to run. Sort of matches up with the error message: An asynchronous module or handler completed while an asynchronous operation was still pending.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900