2016-06-24 6 views
2

私はTwilioの番号にSMSメッセージを送信するTwilioのサンプルSMSアプリケーションを完成させようとしており、Twilioサービスは私に返信を返します。私はTwilioのサービスが私のAPIに到達していることを知っています.Twilioからの私のAPIへの着信要求を見ることができ、私のAPIの応答を見ることができますが、SMS応答を返すことはないので間違っています。TwilioがSMSへのXMLの応答

[HttpPost] 
[Route("EchoTest")] 
public IHttpActionResult EchoTest() 
{ 
    string response = "<Response><Sms>Thanks for the message</Sms></Response>"; 
    return ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, response, new XmlMediaTypeFormatter())); 
} 

私はので、私はIHttpActionResultを返すで一貫してできるResponseMessageを返しています。私は同じ結果を下に示すようにちょうどHttpResponseMessageを返そうとしました。

[HttpPost] 
[Route("EchoTest")] 
public HttpResponseMessage EchoTest() 
{ 
    string response = "<Response><Sms>Thanks for the message</Sms></Response>"; 
    Request.CreateResponse(HttpStatusCode.OK, response, new XmlMediaTypeFormatter()); 
} 

これは私のAPIが返送されたものである...

<string 
xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;Response&gt;&lt;Sms&gt;Thanks for the message&lt;/Sms&gt;&lt;/Response&gt; 
</string> 

は、私はXMLレスポンスをめちゃくちゃですか?私はTwilioに送り返すために探していますと、このです...

<Response><Sms>Thanks for the message</Sms></Response> 

答えて

3

参照のWebページ:https://msdn.microsoft.com/en-us/library/hh969056(v=vs.118).aspx この

XElement response = XElement.Parse("<Response><Sms>Thanks for the message</Sms></Response>"); 
    Request.CreateResponse<XElement>(request, HttpStatusCode.OK, response); 
+0

感謝をお試しください! XElementコードが機能しました。私は 'return Request.CreateResponse (HttpStatusCode.OK、レスポンス、新しいXmlMediaTypeFormatter());を使用して返信しなければならなかったが、 – webworm