private static ServiceRoute MapServiceRoute(Type serviceType, string routePrefix, HttpConfiguration configuration = null, object constraints = null, bool useMethodPrefixForHttpMethod = true)
        {
            if (configuration == null)
                configuration = new WebApiConfiguration(useMethodPrefixForHttpMethod);

            var serviceHostFactory = new HttpServiceHostFactory { Configuration = configuration };
            var webApiRoute = new WebApiRoute(routePrefix, serviceHostFactory, serviceType) { Constraints = new RouteValueDictionary(constraints) };
            return webApiRoute;
        }
示例#2
0
        public T Get <T>(WebApiRoute route, ServerConfiguration webApi, object id)
        {
            if (MockValues.ContainsKey(route))
            {
                return((T)MockValues[route]);
            }

            var client = new HttpClient {
                BaseAddress = webApi == null ? BaseAddress : new Uri(webApi.ToString())
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
            var response = client.GetAsync(WebApiRoutes[route] + "?id=" + id ?? "").Result;

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <T>(response.Content.ReadAsStringAsync().Result));
            }

            throw new HttpRequestException(response.Headers.ToString());
        }
示例#3
0
        public T Patch <T>(WebApiRoute route, object id, object data, ServerConfiguration webApi)
        {
            if (MockValues.ContainsKey(route))
            {
                return((T)MockValues[route]);
            }

            var client = new HttpClient
            {
                BaseAddress = webApi == null ? BaseAddress : new Uri(webApi.ToString())
            };

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
            var content      = new StringContent(JsonConvert.SerializeObject(data), Encoding.Default, "application/json");
            var postResponse = client.PatchAsync(WebApiRoutes[route] + "?id=" + id ?? "", content).Result;

            if (postResponse.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <T>(postResponse.Content.ReadAsStringAsync().Result));
            }

            throw new HttpRequestException(postResponse.Headers.ToString());
        }
示例#4
0
 public T Patch <T>(WebApiRoute route, object id, object data) => Patch <T>(route, id, data, null);
示例#5
0
 public T Patch <T>(WebApiRoute route, object id, ServerConfiguration webApi) =>
 Patch <T>(route, id, null, webApi);
示例#6
0
 public T Put <T>(WebApiRoute route, object data) => Put <T>(route, data, null);
示例#7
0
 public T Put <T>(WebApiRoute route, ServerConfiguration webApi) => Put <T>(route, null, webApi);
示例#8
0
 public T Get <T>(WebApiRoute route) => Get <T>(route, null, null);
示例#9
0
 public T Get <T>(WebApiRoute route, ServerConfiguration webApi) => Get <T>(route, webApi, null);
示例#10
0
 public T Get <T>(WebApiRoute route, object id) => Get <T>(route, null, id);
示例#11
0
 public T Delete <T>(WebApiRoute route) => Delete <T>(route, null, null);
示例#12
0
 public T Delete <T>(WebApiRoute route, object id) => Delete <T>(route, null, id);
示例#13
0
 public T Delete <T>(WebApiRoute route, ServerConfiguration webApi) => Delete <T>(route, webApi, null);