wcf-web-api

C# WCF Web API + JSONP

孤者浪人 提交于 2019-12-17 17:22:08
问题 Is there an easy way to get JSONP working for the new WCF Web API rest services? I've tried this with no luck <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" defaultOutgoingResponseFormat ="Json" crossDomainScriptAccessEnabled="true"/> </webHttpEndpoint> </standardEndpoints> 回答1: https://alexanderzeitler.com/articles/Look-Ma,-I-can-handle-JSONP-%28aka-Cross-Domain-JSON%29-with-WCF-Web-API-and-jQuery!/ Update: Latest WCF

Headers disappearing when using HttpSelfHostServer

左心房为你撑大大i 提交于 2019-12-13 04:12:04
问题 I'm in the process of migrating a rather extensive REST service from WCF to ASP.NET WebAPI. We are using the Authorization header to send tokens from client to the server, and I implemented a DelegateHandler with code that responds with a 401 as soon as it sees there is no valid Authorization header. A simplification of the code can be seen here: public class AuthenticationHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,

Consuming Web Api's as HttpPost

╄→гoц情女王★ 提交于 2019-12-13 03:55:26
问题 Can somebody help me how to post an array of type long to a WebApi. I think I have to use PostAsync from HttpClient, but I am not sure how to put array to HttpContent. This is my controller. [HttpPost] [Authorize] public void UpdateBatchesToReadyToShip(long[] batchIds) { // process request } And this is how I am trying to consume API var buffer = Encoding.ASCII.GetBytes("username:password"); var authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(buffer)); client

WCF WebApi's Self-Hosting not accepting PUT verbs

℡╲_俬逩灬. 提交于 2019-12-12 19:20:29
问题 I have put together a HTTP driven API using the WCF WebAPI that uses the PUT verb. When hosted inside of an MVC3 project that is hosted upon IIS Express, everything works as designed. However, when I unit-test I'm occasionally wanting to test the transport aspects rather than just against my own resources. My unit-tests fail with a 405 - MethodNotAllowed. Again, exactly the same service hosted in IIS works (where I enabled the PUT and DELETE verbs in the configuration file). How can I get the

How to create query expression for Odata for get by Id

北慕城南 提交于 2019-12-12 08:57:47
问题 I have created an OData service and now I am trying to consume this service at client side. I wants to create an expression such as for the below url in the c# query expression- http://odata.org/Product-Service/Product(150) The above url is working fine in browsers but I want to create query expression in the C# for the above url. Any help would be greatly appreciable. 回答1: You could use a DataServiceContext + DataServiceQuery in System.Data.Services.Client to hit the Url. Remember no query

WCF Web API 0.6 - Returning List<T> in HttpResponseMessage throws an exception

你。 提交于 2019-12-12 03:08:43
问题 I'm fairly new to the WCF Web API, I have a basic service going and trying to leverage the full power of using HttpResponseMessage as return type. I am trying to return a List and getting the following error around which I can't get around. This is a very basic straight-up XML service. Any ideas would be appreciated. Thanks. Type 'System.Net.Http.HttpResponseMessage`1[System.Collections.Generic.List`1[Entities.UploadedDocumentSegmentType]]' cannot be serialized. Consider marking it with the

Wcf Web API filter by DateTimeOffset

送分小仙女□ 提交于 2019-12-11 09:22:20
问题 I am currently using WCF Web API Preview 5 and am trying to filter a list of users where the LastModifiedDate is greater than or equal to the provided datetimeoffset: http://api.myapp.com/users?$filter=LastModifiedDate ge datetimeoffset'2011-06-01T14:03:00+00:00Z' However all I am getting is an error saying: Microsoft.ApplicationServer.Query.ParseException: '.' or '(' expected (at index 34) The filtering seems to be working fine as this filter returns the requested user http://api.myapp.com

How to Get Header Values

烂漫一生 提交于 2019-12-11 05:33:46
问题 How can I access header values from a web method in WCF Web API? 回答1: You can try something like this: (using System.Web;) HttpUtility.UrlDecode(HttpContext.Current.Request.Headers["myValue"]); 来源: https://stackoverflow.com/questions/8238690/how-to-get-header-values

BackgroundTransferRequest WP7

依然范特西╮ 提交于 2019-12-11 02:58:37
问题 I am using the Background Transfer to upload Photographs to my Web Service. As the Photograph uploads can consume significant time and memory, I thought it might be a nice idea to use the background transfer request to accomplish this. After the photo is uploaded, I want to obtain the Id of the uploaded photo and then use it for post-processing. However, it turns out I can't do that in a background transfer request. Per my understanding, Background Transfer works using the following logic

C# WCF WebAPI Modify Response's HttpContent

徘徊边缘 提交于 2019-12-11 02:15:57
问题 Using the WCF Web API how would I go about changing a response's content body after the application logic has been run but before it's returned to the user. The goal is if suppressstatuscontent is true we: Add a statuscode field to the content body Change the statuscode on the response to 200 I have overridden a DelegatingChannel and in the SendAsnyc have some code that looks like this: protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken