首页 > 代码库 > Winform简单调用WebApi
Winform简单调用WebApi
WebAPI Controllers
public class SimuController : ApiController { //EF 5 BIM_GENERALDICTONARY_DBEntities entities=new BIM_GENERALDICTONARY_DBEntities(); // GET api/Simu public IEnumerable<T_BIM_PropityClass> Get() { return entities.T_BIM_PropityClass; } }
WinForm Client
static readonly Uri _baseAddress = new Uri("http://localhost:5373/"); static readonly Uri _address = new Uri(_baseAddress, "/api/simu"); private void button1_Click(object sender, EventArgs e) { WebClient webClient = new WebClient(); webClient.Headers["Accept"] = "application/json"; webClient.Encoding = Encoding.UTF8;webClient.DownloadStringCompleted += (send, es) => { if (es.Result != null) { var test = JsonConvert.DeserializeObject<T_BIM_PropityClass[]>(es.Result); if (test.Any()) { gridControl1.DataSource = test;} } else { MessageBox.Show(es.Error.Message); } }; webClient.DownloadStringAsync(_address); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。