У меня проблемы с обработчиком ASHX. Следующий фрагмент кода работает правильно на локальном компьютере, но он не работает на сервере.Async Post в обработчике ASHX
public void ProcessRequest(HttpContext context)
{
...... More code
// convert class to namevaluecollection
NameValueCollection formFields = payloadData.ToNameValueCollection();
using (var client = new WebClient())
{
//client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
client.UploadValuesAsync(new Uri("http://server/accept"), "POST", formFields);
}
}
Я получаю следующее сообщение об ошибке:
Exception type: InvalidOperationException
Exception message: An asynchronous operation cannot be started at this time.
Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle.
If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>.
This exception may also indicate an attempt to call an "async void" method, which is generally unsupported within ASP.NET request processing.
Instead, the asynchronous method should return a Task, and the caller should await it.
EDIT:
Одна вещь, я обнаружил, что это может быть влияние версии на кодовую. Может ли кто-то подтвердить, что UploadValuesAsync ведет себя по-разному на фреймворк 4.5 vs 4.6
Мой обработчик Http не является обработчиком ASYNC, но мне нужно отправить значения асинхронно на другой сервер, чтобы предотвратить блокировку потока. Я хочу опубликовать данные и забыть об этом. – cbps