約10MBのサイズのxmlファイルを返すWebサービス(Asp.net Web APIで作成)があります。
サービスはFiddlerでテストされ、機能しています
HttpClientクラスを使用してファイルをダウンロードしようとしています。await client.GetAsync()
問題は、APIプロジェクトがを返したとしても、コンパイラがメソッドの外に出ることはないということHttpResponseMessage
です。
これが私の機能です
public async Task<XDocument> DownloadXmlAsync(string xmlFileName)
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:51734/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
// When the copiler enters this next command, it doesn't get outside anymore
HttpResponseMessage response = await client.GetAsync("api/applications/ApplicationXml?fileName=" + xmlFileName);
response.EnsureSuccessStatusCode();
string stringResponse = await response.Content.ReadAsStringAsync();
XDocument xDoc = new XDocument(stringResponse);
return xDoc;
}
}
web.configのmaxRequestLengthも更新しました
<httpRuntime maxRequestLength="15360" />
私は何を間違っていますか?
編集
関数を呼び出す
public async Task<ActionResult> Index()
{
var xmlTask = DownloadXmlAsync("1.xml");
// doesn't reach here
var result = xmlTask.Result;
return View();
}