ローカルネットワークマシンにonpremise Webサービス(asp.net core mvc)を導入しました。 AzureにデプロイされたApp Serviceを使用して、これらのWEB APIを呼び出そうとしています。しかし、それはタイムアウトエラーを与えているか"HTTP"プロトコルを使用して接続しようとすると、タスクがキャンセルされたエラー。 「HTTPS」の場合は「セキュリティエラーが発生したエラー」と表示されます。ハイブリッド接続マネージャーを使用してHttpClientを使用してonpremise WEB APIを呼び出すAzure Webアプリケーションサービス
Azure App Serviceでハイブリッド接続を作成し、80と443ポートの両方に対してオンラインで表示されるonpremise Web APIサービスに接続しました。ローカルネットワークマシンにもHybrid Connection Managerをセットアップしました。上記のコード
以下Azureのアプリケーションサービス上で展開されているコードを呼び出すためのコードスニペットである(例えばhttps://xyz.azurewebsite.com)
try
{
var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMinutes(60);
httpClient.BaseAddress = new Uri("https://onpremise");
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
//Simple Get Request to test on-premise service
var response = await httpClient.GetStringAsync("api/OnPremiseData/GetData");
ViewBag.ResponseText = response;
}
私はローカルホストからアプリケーションをデバッグする場合には正常に動作します。だから、私が想定しているコードに問題はありません。以下は
は、Web APIのコードスニペットです:以下[Route("api/[controller]/[action]")]
public class OnPremiseDataController : Controller
{
[HttpGet]
public string GetData()
{
return "Success";
}
}
とstartup.csファイルがある
我々は使用する同様のシナリオ(WebAppのとオンプレミスSQL)とトリックだったpublic void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(options => options.WithOrigins("https://xyz.azurewebsite.com", "https://localhost:44310").AllowAnyMethod().AllowAnyHeader());
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
私は私が考えますエンドポイントに言及するだけでSQL Serverに接続できます。例えば。 tcp:接続文字列内のホスト名のみ、1433。どのように同様の方法で残りのAPIを接続する任意のアイデア?完全修飾名を使用して試してみる必要があります。それが動作することを願っています。 –
接続も成功しましたが、エンドポイントがFQDNになるまで要求は到着しませんでした。 –
うん。 FQDNは私のために働く! HTTPS用ではなくHTTP用です。 HTTPSを使用すると、「セキュリティエラーが発生しました」というメッセージが表示されます。 –