Ich gewöhne mich an die Verwendung von AspNetCore 2.0.500 nicht gefunden Fehler beim Aufruf der Web-API
Ich habe einen WPF-Client und ruft meinen Web-API-Controller auf.
Zuerst ist dies meine Web API (unter Core 2.0).
[Route("api/[controller]")]
public class EmailRecordController : Controller
{
[HttpPost]
[Route("ValidateEmail")]
public EmailRecord ValidateEmail([FromBody] EmailRecord emailRecord)
{
return _externalApiEmailService.Search(emailRecord.email);
}
}
Ich nenne es von meinem WPF-Client:
var uriController = "api/EmailRecord/ValidateEmail";
public async Task<EmailRecord> SearchEmail(
string emailAddress, string uriController)
{
//var uri = "http://localhost:49627//api/Email/Search";
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:49627/");
var emailRecord = new EmailRecord {email = emailAddress};
var jsonInput = JsonConvert.SerializeObject(emailRecord);
var contentPost = new StringContent(jsonInput, Encoding.UTF8, "application/json");
var response = await client.PostAsync(uriController, contentPost).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<EmailRecord>(json);
}
}
My Model auf meinem Client ist:
public class EmailRecord
{
public string CompanyRef { get; set; }
public string ClientRef { get; set; }
public string email { get; set; }
public string did_you_mean { get; set; }
public string user { get; set; }
public string domain { get; set; }
public string format_valid { get; set; }
public string mx_found { get; set; }
public string smtp_check { get; set; }
public string catch_all { get; set; }
public string role { get; set; }
public string disposable { get; set; }
public string free { get; set; }
public string score { get; set; }
}
Mein Modell auf meinem asp.net.core Server ist:
public class EmailRecord
{
public string CompanyRef { get; set; }
public string ClientRef { get; set; }
public string email { get; set; }
public string did_you_mean { get; set; }
public string user { get; set; }
public string domain { get; set; }
public string format_valid { get; set; }
public string mx_found { get; set; }
public string smtp_check { get; set; }
public string catch_all { get; set; }
public string role { get; set; }
public string disposable { get; set; }
public string free { get; set; }
public string score { get; set; }
}
Wenn es aufgerufen wird, bekomme ich das:
- Antwort {Statuscode 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Inhalt: System.Net.Http.StreamContent, Sockel: { X-Quelldateien:? = UTF-8 B ? RDpcREVWLUluZm9ybWVkV29ya2VyXEluZm9ybWVkV29ya2VyXEluZm9ybWVkV29ya2VyXEluZm9ybWVkV29ya2VyXGFwaVxFbWFpbFJlY29yZFxWYWxpZGF0ZUVtYWls = Date: Sun, 10. Dezember 2017 19.58.02 GMT Server: Kestrel X-Powered-By: ASP.NET Content-Length: 0 }} System.Net.Http.HttpResponseMessage
Ich habe eine ähnliche API (nur mit einem anderen Modell/Funktion) und das funktioniert Ok und ich habe das als Vorlage für alle anderen verwendet.
Kann einfach nicht sehen, warum dies ein Fehler ist?
Zusätzlich:
Screenshot Fehler
Es sollte einige zusätzliche Informationen in der Fehlerreaktion geben, Sie haben nicht genug Informationen gegeben, damit wir es beheben können. Sind Sie sicher, dass '_externalApiEmailService.Search' funktioniert? – DavidG
Ich werde es noch einmal laufen lassen und eine weitere Quickwatch machen.Dieser Metode Ich habe einen Haltepunkt gesetzt, bevor es irgendeine Sache läuft, aber ich werde es bekommen, um eine Null zurückzugeben, nur für den Fall, dass der Debugger Break-Point nicht funktioniert - obwohl es auf meiner anderen api –