Adding WebApi To ASPNET Site
Adding WebApi To ASPNET Site
Microsoft /web
WCF Back-end Services SOAP, WS-* Transports: HTTP, TCP, UDP, Queues, WebSockets, custom Message patterns: requestreply, one-way, duplex Use WCF Web HTTP to add HTTP endpoints to existing WCF services Use WCF Data Services for full OData support Microsoft /web
ASP.NET Web API Front-end Services Media Types: JSON, XML, form-URL-encoded, custom HTTP only Request-reply only REST, resource-centric Use SignalR for asynchronous signaling (polling, longpolling, WebSockets)
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
public async Task<IList<string>> Post() { List<string> result = new List<string>(); if (Request.Content.IsMimeMultipartContent()) { MultipartFormDataStreamProvider stream = new MultipartFormDataStreamProvider("c:/uploads/"); IEnumerable<HttpContent> bodyparts = await Request.Content.ReadAsMultipartAsync(stream); IDictionary<string, string> bodyPartFiles = stream.BodyPartFileNames; bodyPartFiles .Select(i => { return i.Key; }) .ToList() .ForEach(x => result.Add(x)); } return result; }
Microsoft /web
Microsoft /web
Microsoft /web
Why Not?
Microsoft /web
Microsoft /web
class Program { static void Main(string[] args) { // configure the server var baseAddress = "http://localhost:8080/"; var config = new HttpSelfHostConfiguration(baseAddress); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Create and open the server var server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); Console.WriteLine("The server is running..."); Console.ReadLine(); } }
Microsoft /web
public class EnvironmentStatus { public string MachineName { get; set; } public DateTime TimeOnServer { get; set; } }
public class EnvironmentController : ApiController { public EnvironmentStatus Get() { Console.WriteLine(User agent " + Request.Headers.UserAgent);
return new EnvironmentStatus { MachineName = Environment.MachineName, TimeOnServer = DateTime.Now }; } }
Microsoft /web
Microsoft /web
Microsoft /web
Microsoft /web
http://forums.dev.windows.com http://bldw.in/SessionFeedback
Microsoft /web