mercredi 6 avril 2016

Multiple operations with path 'api/External' and method 'GET' while calling an external API

I am trying to call an externally hosted Web API within my Web API Application. While attempting to use Get () method, everything seems to work fine. However, when I try to implement Get(int value) I am getting an error: Multiple operations with path 'api/External' and method 'GET'.

What is wrong with my Contorller?

public class ExternalController : ApiController
{
    static string _address = "http://localhost:00000/api/Values";
    private string result;

    // GET api/values
    public async Task<IEnumerable<string>> Get()
    {
        var result = await GetExternalResponse();

        return new string[] { result, "value2" };
    }

    private async Task<string> GetExternalResponse()
    {
        var client = new HttpClient();
        HttpResponseMessage response = await client.GetAsync(_address);
        response.EnsureSuccessStatusCode();
        var result = await response.Content.ReadAsStringAsync();
        return result;
    }


    public async Task<string> Get(int value)
    {
        var result = await GetExternalResponse();

        return result;
    }


}

I have also tried the below approach, which also seems to throw the same error:

private async Task<string> GetExternalResponse2(int value)
    {
        var client = new HttpClient();
        HttpResponseMessage response = await client.GetAsync(_address + "/" + value);            
        response.EnsureSuccessStatusCode();
        var result = await response.Content.ReadAsStringAsync();
        return result;
    }

    public async Task<string> Get(int value)
    {
        var result = await GetExternalResponse2(value);

        return result;
    }




Aucun commentaire:

Enregistrer un commentaire