43 lines
1.3 KiB
C#

using Microsoft.Extension.Core;
using Microsoft.Extension.Net.ApiCommunication;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ApiCommunicationManager.RunServer<ApiRequest,ApiRespond>((ApiRequest data) => {
ApiRespond apiRespond = new ApiRespond();
apiRespond.IsSucess = true;
apiRespond.Msg = "OK";
apiRespond.Datas.Add("intval",99);
apiRespond.Datas.Add("floatval", 99.9f);
apiRespond.Datas.Add("person",new Person() {
Name = data.StationID,//ÇëÇóÊý¾Ý´¦Àí
Age = 18
});
return apiRespond;
});
}
private async void button1_Click(object sender, EventArgs e)
{
this.richTextBox1.Text = "";
await Task.Delay(500);
var ret = ApiCommunicationManager.Request<ApiRequest, ApiRespond>(new ApiRequest() {
StationID = "zys"
});
if (ret.IsSucess)
{
this.richTextBox1.Text = ret.Content.GetJsonString();
}
else
{
MessageBox.Show(ret.Message, "fail");
}
}
}
}