I have a simple web api that will retrieve a image file and return the bytes to the caller. It will work when I host the api project inside visualstudio in local (IIS Express), however, it will fail when I publish this project to my IIS server. Anyone has any idea?
[RoutePrefix("api/v1/Test")]
public class TestController : ApiController
{
[Route("GetBytesCount")]
public async Task<int> GetBytesCount()
{
var client = new HttpClient() { Timeout = new TimeSpan(0, 5, 0) };
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync(@"http://icons.wxug.com/i/c/k/clear.gif");
response.EnsureSuccessStatusCode();
var imageBytes = await response.Content.ReadAsByteArrayAsync();
return imageBytes.Length;
}
}
if I called it from local box
http://localhost:57988/lkr/api/v1/Test/Getbytescount
it will return
int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1689</int>
When I call it from my server, it will return
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Response status code does not indicate success: 503 (Service Unavailable).
</ExceptionMessage>
<ExceptionType>System.Net.Http.HttpRequestException</ExceptionType>
<StackTrace>
......
</StackTrace>
</Error>