asp.net-web-api

How to access a service deployed locally in IIS express from Visual studio emulator for android

…衆ロ難τιáo~ 提交于 2020-01-02 09:14:28
问题 I'm have a WebApi project which gets deployed locally on my machine as http://localhost:6143 or http://127.0.0.1:6143. However when I try to browse to that endpoint on the visual studio emulator for android browser, I get net:err connection timed out. Note that on the emulator I'm using http://10.0.2.2:6143 since localhost won't work on the emulator (since it's a vm, localhost refers to itself). I've also tried 127.0.0.1:6143 and get connection refused. I also added port 6143 to the incoming

Trying to return IEnumerable<dynamic> from ASP.NET Web Api controller

a 夏天 提交于 2020-01-02 07:42:37
问题 I am trying to return an IEnumerable from my ASP.NET Web Api controller .. I have the following in my ApiController ... public IEnumerable<dynamic> Get() { var personRepository = new PersonRepository(); var parameters = HttpUtility.ParseQueryString(Request.RequestUri.Query); return personRepository.GetAll(parameters) .Select(x => new { Name = x.Name }); } When I execute my code I receive the following error ... <Error> <Message>An error has occurred.</Message> <ExceptionMessage> The

How to receive a byte array and json in a Web API Controller

余生长醉 提交于 2020-01-02 07:36:17
问题 I need to receive a json object together with a byte array in a c# Web API application. This is how I am sending the data: public bool SendMedia(string method, Media media) { string filePath = Path.GetFullPath(Path.Combine(filesDirectory, media.FileName)); if (!File.Exists(filePath)) { return false; } using (var client = new HttpClient()) using (var content = new MultipartContent() ) { content.Add(new StringContent(JsonConvert.SerializeObject(media), Encoding.UTF8, "application/json")); byte[

WebAPI RC GetAll with URI parameters

点点圈 提交于 2020-01-02 07:28:28
问题 Previously in WebAPI (beta) I was able to create a "GetAll" method that took in optional parameters added on the URI: http://localhost/api/product?take=5&skip=10 This still seems to work but only if I include all the parameters. In (beta), I could omit the parameters ( http://localhost/api/product/ ) and the "GetAll" method would get called (take & skip would be null). I could also omit some of the parameters http://localhost/api/product?take=5 (skip would be null) public IEnumerable

Protobuf-net root serialization integrity

↘锁芯ラ 提交于 2020-01-02 07:01:14
问题 I have two objects which reference each other. [JsonObject(IsReference = true)] [DataContract(IsReference = true, Namespace = "http://schemas.datacontract.org/2004/07/TrackableEntities.Models")] [ProtoContract] public class ProtoBufObject : ITrackable { [DataMember(Order = 3)] public Guid Oid { get; set; } [DataMember(Order = 4)] [ProtoMember(4, AsReference = true)] public ChildProtoBufObject child { get; set; } [DataMember(Order = 1)] public TrackingState TrackingState { get; set; }

Get Xamarin Android Device calling ASP.NET Web APi running Localhost

天涯浪子 提交于 2020-01-02 06:58:11
问题 I've managed to use the following guide for enabling my VS2015 Android Emulator access to a ASP.NET WEP API running on my local-host which is great :- http://briannoyesblog.azurewebsites.net/2016/03/06/calling-localhost-web-apis-from-visual-studio-android-emulator/ But i would also like to configure my Xamarin application for enabling my external android device the same access to the web api. At present, when running from device, the webclient makes the request but it never completes, which

Retrieve bearer token in ASP.NET WebAPI

谁都会走 提交于 2020-01-02 06:20:18
问题 I have a Web API with authentication enabled (bearer token). This is called by a client application and I want to protect it from anonymous usage so I would like to create a single user and create a bearer token for it. I can create the token by calling the register and token methods, but I would like to do this from code. As far as I know, the bearer token is not stored in the database. Can it be retrieved somehow using the ASP.NET Identity API ? I would also like to create this user from

WebAPI CORS and Ninject

点点圈 提交于 2020-01-02 06:20:10
问题 I have a c# WebAPI project that has ninject and all the get functions are working. However every time i try to post i get a "Method Not Allowed" response from the api. I have read a few places that this is cause when the api is refusing cross origin calls. So i used the package manager console and installed the Microsoft.AspNet.WebApi.Cors nugent package and followed the instructions as per the article http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api. My

ASP NET Web API Route templates

我怕爱的太早我们不能终老 提交于 2020-01-02 06:17:24
问题 I have an entity named Agency with following apis GET http://localhost:37331/api/agency?start=1&limit=10&status=1 GET http://localhost:37331/api/agency/2 POST http://localhost:37331/api/agency PUT http://localhost:37331/api/agency DELETE http://localhost:37331/api/agency/4 POST http://localhost:37331/api/agency/activate/3 POST http://localhost:37331/api/agency/deactivate/3 GET http://localhost:37331/api/agency/types The route templates I used are config.Routes.MapHttpRoute( name:

ASP NET Web API Route templates

亡梦爱人 提交于 2020-01-02 06:17:00
问题 I have an entity named Agency with following apis GET http://localhost:37331/api/agency?start=1&limit=10&status=1 GET http://localhost:37331/api/agency/2 POST http://localhost:37331/api/agency PUT http://localhost:37331/api/agency DELETE http://localhost:37331/api/agency/4 POST http://localhost:37331/api/agency/activate/3 POST http://localhost:37331/api/agency/deactivate/3 GET http://localhost:37331/api/agency/types The route templates I used are config.Routes.MapHttpRoute( name: