Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

OWIN batch requests

$
0
0

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


Viewing all articles
Browse latest Browse all 4850

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>