Custom Media formatter – HttpClient

send file from one solution to other solution Client public void¬†UploadDomainAssembly(string filename) { String strFile = System.IO.Path.GetFileName(filename); using (var client = new HttpClient()) using (var content = new MultipartFormDataContent()) { // Make sure to change API address client.BaseAddress = new Uri(“http://localhost:8090/”); var fileContent = new ByteArrayContent(File.ReadAllBytes(filename)); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue(“AssemblyAttachment”) { FileName = strFile };… Read More Custom Media formatter – HttpClient

Custom Media formatter

for byte[] send a file into stream (byte[]) and get uploaded into other solution. Add new class to web api service public class BinaryMediaTypeFormatter : MediaTypeFormatter { private static Type _supportedType = typeof(byte[]); private const int BufferSize = 8192; // 8K public BinaryMediaTypeFormatter() { SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue(“application/octet-stream”)); } public override bool CanReadType(Type type) { return type… Read More Custom Media formatter

Api Versioning – with header and with url

  WebApiConfig.cs public static class WebApiConfig { public static void Register(HttpConfiguration config) { //// CODE IS FOR VERSIONING USING HEADER config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: “DefaultApi”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional } ); config.Services.Replace(typeof(IHttpControllerSelector), new CustomControllerSelector((config))); // //// CODE IS FOR VERSIONING USING URL //var constraintsResolver = new DefaultInlineConstraintResolver(); //constraintsResolver.ConstraintMap.Add(“apiVersion1Constraint”, typeof(ApiVersion1Constraint)); //constraintsResolver.ConstraintMap.Add(“apiVersion2Constraint”, typeof(ApiVersion2Constraint)); //config.MapHttpAttributeRoutes(constraintsResolver);… Read More Api Versioning – with header and with url