Web Api成功调用操作后不返回。 [英] Web Api Is not returning after action is successfully invoked.

查看:86
本文介绍了Web Api成功调用操作后不返回。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成功调用操作后,Web Api未返回。



以下是我要调用的操作

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");
                ss.SetOutputToWaveFile(filePath);
                ss.Speak(word);
                ss.SetOutputToNull();
                ss.Dispose();
            }
            return names;
        }
}





从浏览器的角度来看,页面继续循环,等待响应,之后这个方法已成功返回字符串数组。



有谁知道为什么这个方法没有将结果返回给浏览器?是否有可能异步线程仍在运行?我调试了这个方法并调用它并成功返回。



干杯,

robNo。



更新



这是一个测试,我期待结果包含静态数组。我想要完成的只是确保我可以在我的托管环境中使用System.Speech程序集,但首先我想让它在本地工作。



< b>更新2



我注释掉了using语句,我在浏览器中成功地将静态数组作为xml接收了。因此,它导致问题的System.Speech代码



我最终收到了浏览器上的错误消息:异步模块或处理程序完成时异步操作仍在等待。



这个错误对我来说很奇怪,因为根据我从MSDN收集的信息,我正在使用的SpeechSynthesizer方法是同步的,这就是我想要的。



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.

Cheers,
robNo.

Update

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.

推荐答案

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;
}





不能声称知道原因,但注释掉粗线,这完美地运作,取消注释它,你听到了文字,但没有回应。合成器中的某些内容必须与Web API框架冲突,或者响应时间过长。在这个和评论之间,我不能帮助我更多。就个人而言,我会考虑使合成调用异步。



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.


这篇关于Web Api成功调用操作后不返回。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆