2017-10-01 20 views
0

により閉鎖されたこんにちは、それは私の時間の3日間を取得するが、まだ生きている、MVCのAPIコアは、既存の接続はリモートホストに強制的

これはMVC APIコアAPIのプロジェクト作業の罰金を消費MVCコアで私のコードです地元にあり、郵便配達

string Baseurl = "http://api.site.com"; 

    // GET: CustomerTypes 
    public async Task<IActionResult> Index() 
    { 
     List<CustomerType> empInfo = new List<CustomerType>(); 
     using (var client = new HttpClient()) 
     { 
      client.BaseAddress = new Uri(Baseurl); 

      client.DefaultRequestHeaders.Clear(); 
      client.DefaultRequestHeaders.Add("Connection", "Keep-Alive"); 
      client.DefaultRequestHeaders.Add("Keep-Alive", "3600"); 
      //Define request data format 
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 

      //Sending request to find web api REST service resource GetAllEmployees using HttpClient 
      HttpResponseMessage res = await client.GetAsync("/api/customerTypes"); 
      if (res.IsSuccessStatusCode) 
      { 
       //Storing the response details recieved from web api 
       var empResponse = res.Content.ReadAsStringAsync().Result; 

       //Deserializing the response recieved from web api and storing into the Employee list 
       empInfo = JsonConvert.DeserializeObject<List<CustomerType>>(empResponse); 

      } 
      //returning the employee list to view 
      return View(empInfo); 
     } 

によってテストされ、これは、MVC APIプロジェクトでstartup.csに設定され

public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddCors(options => 
     { 
      options.AddPolicy("AllowSpecificOrigin", 
       builder => builder.AllowAnyOrigin() 
       .AllowAnyMethod() 
       .AllowAnyHeader() 
       .AllowCredentials() 
       ); 
     });} 

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 


     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
     } 
     // app.UseCorsMiddleware(); 

     // Shows UseCors with named policy. 
     app.UseCors("AllowSpecificOrigin"); 



     app.UseMvc(); 
    } 

そして、制御あたりのAPIセットの制御[EnableCors( "AllowSpecificOrigin")]で

は、私は多くの方法を試してください:郵便配達リモートサイトでローカル

、3-コールリモートAPIからリモートおよびCALにAPIを公開するローカルから の1-実行APIおよびリモートWeb

2 - で呼び出す

この

すべてが機能しないと、ポストマンによってコールローカルAPIは、要求の処理中に未処理の例外が発生した

働いていたときにのみ。

のSocketException:既存の接続が強制的にリモート・ホストによって閉じた System.Net.Sockets.Socket.EndReceive(たIAsyncResult asyncResult)

のIOException:トランスポート接続からデータを読み取ることができません:既存の接続が強制的でしたリモートホストによって閉じられます。 System.Net.ConnectStream.EndRead(IAsyncResult asyncResult)

HttpRequestException:コンテンツをストリームにコピー中にエラーが発生しました。 System.Net.Http.HttpContent + d__49.MoveNext()私の場合の

答えて

0

、私はホストマネージャと連絡し、彼らは、IISをリセットし、それは私のために働きます。

関連する問題