wcf-web-api

Working with System.Threading.Tasks.Task<Stream> instead of Stream

最后都变了- 提交于 2019-12-09 10:51:40
问题 I was using a method like below on the previous versions of WCF Web API: // grab the posted stream Stream stream = request.Content.ContentReadStream; // write it to using (FileStream fileStream = File.Create(fullFileName, (int)stream.Length)) { byte[] bytesInStream = new byte[stream.Length]; stream.Read(bytesInStream, 0, (int)bytesInStream.Length); fileStream.Write(bytesInStream, 0, bytesInStream.Length); } But on the preview 6, HttpRequestMessage.Content.ContentReadStream property is gone. I

Validating model properties WCF Web APi

一世执手 提交于 2019-12-09 06:34:48
问题 I have a set of services hosted with WCF Web Api, what I need to do is validate the properties inside the models of the app. In MVC 3 for example I decorate properties in the model like this: [StringLength(30)] public string UserName { get; set; } and then in the controller I proceed like this to verify os the model has met the validation parameters: [HttpPost] ActionResult Create(Model myModel) { if(ModelState.IsValid(){ Post the model } else { Don't post the model } } Is there a way to do

how to call cross-domain web api using ajax?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 21:24:31
问题 jQuery.ajax({ type: "GET", url: 'http://example.com/restaurant/VeryLogin(username,password)', dataType: "json", success: function (data) { alert(data); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("error"); } }); it alerts success, but data was null. The url returns xml data, if we specify the dataType we can get the json data,but here it was not getting any data. Any help appreciated. 回答1: Javascript is subject to the same domain policy. This means for security a JS

Massive with WCF Web Api to return dynamic types/Expandos?

感情迁移 提交于 2019-12-07 19:57:55
问题 I want to use Massive for data access with WCF Web Api and return either dynamic or ExpandoObject / IEnumerable<ExpandoObject> from my web api. I have this basically working using a JsonNetMediaTypeFormatter which uses Json.NET's ExpandoObject serialization, but everything gets returned as a Key-Value pairs in the Json such as: [ { "Key":"ID", "Value":"1000" }, { "Key":"FirstName", "Value":"John" }, { "Key":"LastName", "Value":"Smith" } ] But, what I want is: [ { "ID":"1000", "FirstName":

how to pass Json array in string - webapi in asp

主宰稳场 提交于 2019-12-07 17:20:28
问题 I am using post method in that method i want to pass entire Json in string like this way {Data:" JsonArray"} in Jssonarray I want to pass this value { "version" : 2, "query" : "Companies, CA", "begin" : 1, "end" : 3, "totalResults" : 718, "pageNumber" : 0, "results" : [ { "company" : "ABC Company Inc.", "city" : "Sacramento", "state" : "CA" } , { "company" : "XYZ Company Inc.", "city" : "San Francisco", "state" : "CA" } , { "company" : "KLM Company Inc.", "city" : "Los Angeles", "state" : "CA

WCF Web API preview 6: No 'MediaTypeFormatter' is available

点点圈 提交于 2019-12-06 13:15:13
I'm looking at using HttpClient in WCF Web API Preview 6 to consume a third party service. This third party service accepts and returns XML formatted data. Their HTTP responses have the Content-Type header set to text/plain. It appears that having the response Content-Type set to text/plain is causing problems. I'm making the request to the service as follows: Task<HttpResponseMessage> result = client.PostAsync(apiEndpoint, new ObjectContent(typeof (LeaveAccrualRequest), request)); Using Fiddler, I can see the request go to the service and an appropriate, expected response come back. However

Uploading files WCF Web API Endpoint

a 夏天 提交于 2019-12-06 12:13:19
问题 Is there any way to upload a file to WCF web API endpoint? If so, how can I access Network Stream to read data? Any help is very much appreciated. Thanks. 回答1: Assuming you are talking about on the client side: One way to do it is to create a FileContent class that derives from HttpContent. In the overrides you will be given the NetworkStream when the HTTPClient is ready to receive the stream. If you are asking about the server side, then you can simply get hold of the HTTPRequestMessage and

Updating foreign key entities in Entity Framework 4.1

泄露秘密 提交于 2019-12-06 12:07:15
问题 I'm currently building a REST service using WebApi and the backing store is using EF4.1. I've run into a snag whereby I cannot update the foreign key... The 2 model classes look like: public class User { [Key] public int UserId { get; set; } public string Name { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Gender { get; set; } // // Membership public Membership Membership { get; set; } } public class Membership: Base { [Key] public int

How does WCF WebApi map a request URI to the appropriate service type / operation?

徘徊边缘 提交于 2019-12-06 12:07:05
问题 How does WCF REST (and WCF WebApi) map a Uri to the correct service endpoint? Within the context of WCF WebApi Preview 4: Inside a custom delegating channel, I would like to find the associated route prefix or service Type based on the incoming HttpRequestMessage.RequestUri. So for instance, RouteTable.Routes.MapServiceRoute<ManagersResource>("employees/managers", config); RouteTable.Routes.MapServiceRoute<EmployeesResource>("employees", config); Say a request comes in for http://server

Massive with WCF Web Api to return dynamic types/Expandos?

我是研究僧i 提交于 2019-12-06 07:30:15
I want to use Massive for data access with WCF Web Api and return either dynamic or ExpandoObject / IEnumerable<ExpandoObject> from my web api. I have this basically working using a JsonNetMediaTypeFormatter which uses Json.NET's ExpandoObject serialization, but everything gets returned as a Key-Value pairs in the Json such as: [ { "Key":"ID", "Value":"1000" }, { "Key":"FirstName", "Value":"John" }, { "Key":"LastName", "Value":"Smith" } ] But, what I want is: [ { "ID":"1000", "FirstName":"John", "LastName":"Smith", } ] As if I were using a concrete type like: public class Customer { public int