TwiML App unexpected end of call: Cannot find the declaration of element 'response'

谁都会走 提交于 2019-12-02 03:11:53

问题


I created TwiML application and set Voice request URL the web deployed ASP.NET-MVC aplication action method: http://voiceapp-001-site1.myasp.net/voice

This action method is invoked when somebody goes to the URL posted above:

 public ActionResult Voice() {

            Response.ContentType = "text/xml";

            // put a phone number you've verified with Twilio to use as a caller ID number
            string callerId = Settings.TwilioNumber;

            // put your default Twilio Client name here, for when a phone number isn't given
            string number = "jenny";

            // get the phone number from the page request parameters, if given
            if (Request["PhoneNumber"] != null) {
                number = Request["PhoneNumber"];
            }

            // wrap the phone number or client name in the appropriate TwiML verb
            // by checking if the number given has only digits and format symbols
            string numberOrClient;
            var m = Regex.Match(number, @"^[\d\+\-\(\) ]+$");
            if (m.Success) {
                numberOrClient = string.Format("<Number>{0}</Number>", number);
            } else {
                numberOrClient = string.Format("<Client>{0}</Client>", number);
            }
            ViewBag.CallerId = callerId;
            ViewBag.NumberOfClient = numberOrClient;
            return View();
        }

The Voice view looks like:

<?xml version="1.0" encoding="UTF-8" ?>
<response>
    <dial callerid="@ViewBag.CallerId">
        @Html.Raw(ViewBag.NumberOfClient)
    </dial>
</response>

Then I try to make test call:

but after 13 seconds call is automatically terminated and In the error log I get:

Notification SID NOe85ffe80dfc52e81f942a7414c9f7c9c
Warning 12200 Schema validation warning
Description Cannot find the declaration of element 'response'.

But below in the Body section I can see the element response:


回答1:


Hi Twilio developer evangelist here.

Can you try modifying your view to look like this instead?

<?xml version="1.0" encoding="UTF-8" ?>
<Response>
    <Dial callerId="@ViewBag.CallerId">
        @Html.Raw(ViewBag.NumberOfClient)
    </Dial>
</Response>

Remember XML is case-sensitive, so the casing in your XML tags actually matter. Also, I would suggest using the Twilio.TwiML helper library. With that, you can get your XML generated for you with the right casing, and avoiding typos altogether.

Here's how you'd do it:

var twiml = new TwilioResponse();
var dialAttributes = new {callerId = "48326304351"};

var dial = twiml.Dial("+15555555555", dialAttributes);
return TwiML(dial);


来源:https://stackoverflow.com/questions/30605151/twiml-app-unexpected-end-of-call-cannot-find-the-declaration-of-element-respon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!