wcf-web-api

Wcf Web Api service routes conflicting with regular asp.net mvc routes (web api preview 4)

泪湿孤枕 提交于 2019-12-06 07:29:20
问题 I noticed that my mvc app is creating wrong url's when using: @using (Html.BeginForm("Test", "Test")) { <input type="submit" value="Submit" /> } This is the generated html source: <form action="/books?action=Test&controller=Test" method="post"> Notice that action starts with /books . This is WRONG! What I've noticed is that Html.BeginForm is always including the beginning of the first web api which has been registered with MapServiceRoute. (see code below) public static void RegisterRoutes

Reading content to the memory from the multi-part file upload

南楼画角 提交于 2019-12-06 04:19:14
I have a problem reading uploaded XML file to the string instead of file. My problem is that when I try to access the stream ( var stream = part.ContentReadStream ) then it's closed. I have feeling that it is accessing closed file stream. Am I using MultipartFormDataStreamProvider incorrectly? File size is only few kilobytes, so that should not be a problem. [WebInvoke(Method = "POST", UriTemplate = "{importFile}")] public HttpResponseMessage Upload(string importFile, HttpRequestMessage request) { if (!request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode

how to pass Json array in string - webapi in asp

元气小坏坏 提交于 2019-12-05 20:23:30
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" } ] } When i pass this I am getting 500 internal Error Please help me how to pass Entire Json in a

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

天大地大妈咪最大 提交于 2019-12-04 17:20:57
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/employees/John How does WCF map this to the correct endpoint? By the time the ResourceFactoryProvider has

Uploading files WCF Web API Endpoint

笑着哭i 提交于 2019-12-04 15:09:54
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. 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 access the httpRequestMessage.Content.ContentReadStream property. Update By default the WCF Transport is

How to create query expression for Odata for get by Id

守給你的承諾、 提交于 2019-12-04 13:14:56
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. You could use a DataServiceContext + DataServiceQuery in System.Data.Services.Client to hit the Url. Remember no query is executed until the call to First() due to lazy loading. var context = new DataServiceContext(new Uri("http

Programmatically set InstanceContextMode

£可爱£侵袭症+ 提交于 2019-12-04 09:52:11
问题 Is there a way to do this ... [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] ...programmatically? The reason is that I want to pass in an instance of my service directly into my self-hosting helper class when integration testing my service. I'm using Castle Windsor to create all my objects, which works fine when using the test web site. But I get the following error when I try to use my HttpWebService helper class ... System.InvalidOperationException was unhandled by user

DELETE method .NET WebAPI does not work

房东的猫 提交于 2019-12-04 02:15:38
问题 I've seen tons of posts about this, but the DELETE method of my new WebAPI simply does not work and returns a 404, using Windows 7 32-bit, IIS 7.5. I've tried Uninstalling WebDAV Adding PUT, DELETE, OPTIONS to the ExtensionlessUrlHandler-Integrated-4.0 handler (and 32bit/64bit handlers). Allowing all modules to run. All to no avail and all return 404. If I change the DELETE type to a GET, then the service runs the GET command perfectly fine. Anyone with any other ideas about this? It's

ASP.NET Web Api Routing Customization

匆匆过客 提交于 2019-12-04 01:45:48
I have WebApi controllers that end with the "Api" suffix in their names (For ex: StudentsApiController, InstructorsApiController). I do this to easily differentiate my MVC controllers from WebApi controllers. I want my WebApi routes to look similar to http://localhost:50009/api/students/5 and not http://localhost:50009/api/studentsapi/5 . Currently to achieve this, I am setting up routes like routes.MapHttpRoute( name: "GetStudents", routeTemplate: "api/students/{id}", defaults: new { controller = "StudentsApi", id = RouteParameter.Optional }); routes.MapHttpRoute( name: "GetInstructors",

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

删除回忆录丶 提交于 2019-12-03 13:21:47
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 believe that it now should look like this one: // grab the posted stream System.Threading.Tasks.Task