/// <summary>
        /// SaveDictionary HTTP post handler
        /// </summary>
        /// <param name="parameters">Dictionary entries</param>
        /// <param name="post">Request from the web page</param>
        /// <returns></returns>
        private IEnumerator <ITask> SaveDictionaryHttpPostHandler(NameValueCollection parameters, HttpPost post)
        {
            string[] entryTexts          = parameters.GetValues("DictEntryText[]");
            string[] entrySemanticValues = parameters.GetValues("DictEntrySemanticValue[]");

            if (entryTexts == null || entrySemanticValues == null ||
                entryTexts.Length != entrySemanticValues.Length)
            {
                PostHttpPostParameterError(post, "Both dictionary entry texts and semantic values "
                                           + "must be posted, and occur in the same quantities");
            }

            // Set up replace request with new grammar dictionary for SpeechRecognizer service
            sr.SpeechRecognizerState srState = new sr.SpeechRecognizerState();
            srState.GrammarType = sr.GrammarType.DictionaryStyle;

            srState.DictionaryGrammar = new DssDictionary <string, string>();
            try
            {
                for (int i = 0; i < entryTexts.Length; i++)
                {
                    srState.DictionaryGrammar.Add(entryTexts[i].Trim(), entrySemanticValues[i].Trim());
                }
            }
            catch (Exception ex)
            {
                post.ResponsePort.Post(new HttpResponseType(
                                           HttpStatusCode.OK,
                                           Fault.FromException(ex)
                                           ));
                yield break;
            }

            // Post replace request to SpeechRecognizer service and check outcome
            sr.Replace replaceRequest = new sr.Replace(srState);
            _srPort.Post(replaceRequest);

            yield return((Choice)replaceRequest.ResponsePort);

            Fault fault = (Fault)replaceRequest.ResponsePort;

            if (fault != null)
            {
                post.ResponsePort.Post(new HttpResponseType(
                                           HttpStatusCode.OK,
                                           fault
                                           ));
                yield break;
            }

            _state.SpeechRecognizerState = srState;

            post.ResponsePort.Post(new HttpResponseType(
                                       HttpStatusCode.OK,
                                       HttpPostSuccess.Instance
                                       ));
            yield break;
        }
        /// <summary>
        /// UseExistingSrgsFile HTTP post handler
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="post"></param>
        /// <returns></returns>
        private IEnumerator <ITask> UseExistingSrgsFileHttpPostHandler(NameValueCollection parameters, HttpPost post)
        {
            string srgsFileLocation = parameters["SrgsFileLocation"];

            if (srgsFileLocation == null || srgsFileLocation.Trim().Length == 0)
            {
                PostHttpPostParameterError(post, "No SRGS file location was specified");
                yield break;
            }

            // Set up replace request with SRGS file location set
            sr.SpeechRecognizerState srState = new sr.SpeechRecognizerState();
            srState.GrammarType      = sr.GrammarType.Srgs;
            srState.SrgsFileLocation = srgsFileLocation.Trim();

            // Post replace request to SpeechRecognizer service and check outcome
            sr.Replace replaceRequest = new sr.Replace(srState);
            _srPort.Post(replaceRequest);

            yield return((Choice)replaceRequest.ResponsePort);

            Fault fault = (Fault)replaceRequest.ResponsePort;

            if (fault != null)
            {
                post.ResponsePort.Post(new HttpResponseType(
                                           HttpStatusCode.OK,
                                           fault
                                           ));
                yield break;
            }

            _state.SpeechRecognizerState = srState;

            post.ResponsePort.Post(new HttpResponseType(
                                       HttpStatusCode.OK,
                                       HttpPostSuccess.Instance
                                       ));
            yield break;
        }
 /// <summary>
 /// Speech recognizer replace handler
 /// </summary>
 /// <param name="replace"></param>
 private void SpeechRecognizerReplaceHandler(sr.Replace replace)
 {
     _state.SpeechRecognizerState = replace.Body;
 }