How to configurate batch route in OWIN?
Before it I had Self-hosted WebApi and I did this way:
_webApiServer = new WebApiServer(..............
var config = _webApiServer.CreateDefaultConfig();
ConfigureBatchRoute(config);
private void ConfigureBatchRoute(HttpSelfHostConfiguration configuration)
{
const string batchRouteName = "WebApiBatch";
var batchRoute = configuration.Routes.MapHttpBatchRoute(batchRouteName, "api/$batch", new XxxxxHttpBatchHandler(_webApiServer.Server));
}
public class XxxxxHttpBatchHandler: DefaultHttpBatchHandler
{
public XxxxxHttpBatchHandler(WebApiServer webApiServer)
: base(webApiServer.Server)
public override async Task<IList<HttpRequestMessage>> ParseBatchRequestsAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
...........................
return requestMessages;
}
public HttpConfiguration CreateDefaultConfig()
{
var config = new HttpSelfHostConfiguration(host);
return config
}
public bool Start(HttpSelfHostConfiguration config)
{
Server = new HttpSelfHostServer(Configuration);
....
}
Now I do this way and it doesn't work
_webApiServer = new WebApiServer(..............
var config = _webApiServer.CreateDefaultConfig();
ConfigureBatchRoute(config);
private void ConfigureBatchRoute(HttpConfiguration configuration)
{
const string batchRouteName = "WebApiBatch";
var batchRoute = configuration.Routes.MapHttpBatchRoute(batchRouteName, "api/$batch", new XxxxxHttpBatchHandler(new HttpServer(configuration));
//Doesn't work too. Sample I took from web-api-2-recipes book var batchRoute = configuration.Routes.MapHttpBatchRoute(batchRouteName, "api/batch",new DefaultHttpBatchHandler(new HttpServer(configuration, new HttpRoutingDispatcher(configuration))));
}
public class XxxxxHttpBatchHandler: DefaultHttpBatchHandler
{
public XxxxxHttpBatchHandler(HttpServer httpServer)
: base(httpServer)
public override async Task<IList<HttpRequestMessage>> ParseBatchRequestsAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
...........................
return requestMessages;
}
public HttpConfiguration CreateDefaultConfig()
{
var httpConfiguration = new HttpConfiguration();
return config;
}
public bool Start(HttpConfiguration config)
{
_webApiService = WebApp.Start(
new StartOptions(_url), appBuilder => {appBuilder.UseWebApi(config);});
}
Message error: Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'.
Parameter name: content