wcf-web-api

JSON.NET Serializer for WCF REST Services

瘦欲@ 提交于 2019-11-27 08:57:56
I am trying to use the NETFx Json.NET MediaTypeFormatter nuget package to swap out the default DataContractJsonSerializer in my WCF REST service (4.0 framework). I downloaded the package in my project and added the following lines of code in the Global.asax file. void Application_Start(object sender, EventArgs e) { RegisterRoutes(); // Create Json.Net formatter serializing DateTime using the ISO 8601 format var serializerSettings = new JsonSerializerSettings(); serializerSettings.Converters.Add(new IsoDateTimeConverter()); var config = HttpHostConfiguration.Create(); config.Configuration

Return either xml or json from MVC web api based on request

一笑奈何 提交于 2019-11-27 05:22:16
问题 Given the following webapiconfig; config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); and this controller; public class ProductsController : ApiController { Product[] _products = new Product[] { new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, new Product { Id = 3, Name = "Hammer", Category = "Hardware",

HttpClient authentication header not getting sent

孤街浪徒 提交于 2019-11-27 02:06:37
问题 I'm trying to use an HttpClient for a third-party service that requires basic HTTP authentication. I am using the AuthenticationHeaderValue . Here is what I've come up with so far: HttpRequestMessage<RequestType> request = new HttpRequestMessage<RequestType>( new RequestType("third-party-vendor-action"), MediaTypeHeaderValue.Parse("application/xml")); request.Headers.Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes( string

Unable to authenticate to ASP.NET Web Api service with HttpClient

為{幸葍}努か 提交于 2019-11-26 16:01:55
I have an ASP.NET Web API service that runs on a web server with Windows Authentication enabled. I have a client site built on MVC4 that runs in a different site on the same web server that uses the HttpClient to pull data from the service. This client site runs with identity impersonation enabled and also uses windows authentication. The web server is Windows Server 2008 R2 with IIS 7.5. The challenge I am having is getting the HttpClient to pass the current windows user as part of its authentication process. I have configured the HttpClient in this manner: var clientHandler = new

POSTing JsonObject With HttpClient From Web API

拜拜、爱过 提交于 2019-11-26 14:03:58
I'm trying to POST a JsonObject using HttpClient from Web API. I'm not quite sure how to go about this and can't find much in the way of sample code. Here's what I have so far: var myObject = (dynamic)new JsonObject(); myObject.Data = "some data"; myObject.Data2 = "some more data"; HttpClient httpClient = new HttpClient("myurl"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = httpClient.Post("", ???); I think I need to cast my JsonObject as a StreamContent but I'm getting hung up on that step. With the new

What&#39;s the difference between WCF Web API and ASP.NET Web API

岁酱吖の 提交于 2019-11-26 11:58:43
问题 I\'ve done a bit of work in the past using WCF WebAPI and really liked a lot of its features, I\'m just playing with ASP.NET Web API at the moment and it seems completely different (IE completely removed from WCF). Does anyone know which features of WCF WebAPI are included in ASP.NET 4 Web API? 回答1: Ive done a little more reading around this and found a few pages by MS people on this: http://wcf.codeplex.com/wikipage?title=How%20to%20Migrate%20from%20WCF%20Web%20API%20to%20ASP.NET%20Web%20API

Unable to authenticate to ASP.NET Web Api service with HttpClient

[亡魂溺海] 提交于 2019-11-26 05:57:48
问题 I have an ASP.NET Web API service that runs on a web server with Windows Authentication enabled. I have a client site built on MVC4 that runs in a different site on the same web server that uses the HttpClient to pull data from the service. This client site runs with identity impersonation enabled and also uses windows authentication. The web server is Windows Server 2008 R2 with IIS 7.5. The challenge I am having is getting the HttpClient to pass the current windows user as part of its

POSTing JsonObject With HttpClient From Web API

*爱你&永不变心* 提交于 2019-11-26 02:16:39
问题 I\'m trying to POST a JsonObject using HttpClient from Web API. I\'m not quite sure how to go about this and can\'t find much in the way of sample code. Here\'s what I have so far: var myObject = (dynamic)new JsonObject(); myObject.Data = \"some data\"; myObject.Data2 = \"some more data\"; HttpClient httpClient = new HttpClient(\"myurl\"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(\"application/json\")); HttpResponseMessage response = httpClient.Post(\"\"