APIのURLを使用せずに別のクラスからアプリケーションAPIコントローラを呼び出す方法はありますか?例えば内部APIコントローラにアクセスする
私はどのように私は、Web要求を使用してに頼ることなく、同じアプリケーション内の別のC#クラスで、このメソッドからJSON結果にアクセスすることができます
public async Task<ActionResult> GetPersonRecord(string id)
{
Person person;
var link = "api/entity/Person/" + id + "?format=json";
string results = await OneIMAction(link);
person = JsonConvert.DeserializeObject<Person>(results);
string json = JsonConvert.SerializeObject(person, Formatting.Indented);
return Content(json, "application/json");
}
「personContoller」でこの方法がありますか?それは可能ですか?
この実装をサービスの背後に隠し、必要な場所に呼び出す必要があります。 – Fals
何かこの回答が議論しているようなものなのでしょうか? https://stackoverflow.com/questions/14887871/creating-a-service-layer-for-my-mvc-application –
「結果」文字列を逆シリアル化して、もう一度あなたの「人」をシリアル化するのは何ですか? – phuzi