私の WebApi はローカル マシンで完全に動作しますが、Azure (Azure Web サイト) に公開すると、次のようになります。
要求 URI ' http://myazurewebsite.domain/Api/Zipcode/GetLatLong?zip5=23423 'に一致する HTTP リソースが見つかりませんでした。
しかし、ローカルホストではうまく機能します。
http://localhost/Api/Zipcode/GetLatLong?zip5=20024
{"Latitude":38.89,"Longitude":-77.03}
変更された WebApi ルートがあります。
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultPublicApi",
routeTemplate: "Api/{controller}/{action}/{id}/{format}",
defaults: new { id = RouteParameter.Optional, format = RouteParameter.Optional}
);
}
}
ApiController クラス:
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Project.Geography.Services;
using Project.WebPublic.Filters;
namespace Project.WebPublic.Controllers.WebApi
{
public class ZipCodeController : ApiController
{
private readonly ZipCodeService _zipCodeService;
public ZipCodeController(ZipCodeService zipCodeService)
{
_zipCodeService = zipCodeService;
}
[HttpGet]
[TransactionFilter]
public HttpResponseMessage GetLatLong(string zip5)
{
if (zip5.Length != 5)
return Request.CreateResponse(HttpStatusCode.BadRequest, "Zip Code Length Not Equal to 5");
var zip = _zipCodeService.GetByZip5(zip5);
if (zip == null)
return Request.CreateResponse(HttpStatusCode.NotFound, "Could not find Zip Code in Database");
var latlong = new
{
Latitude = zip.Latitude,
Longitude = zip.Longitude
};
return Request.CreateResponse(HttpStatusCode.OK, latlong);
}
}
}