hi guys,, l'm learn how to consume wep api from windows form, when I try consume wep api using webform run properly and can cunsume all method, but when I'm consume wep api from windows form I'm getting error with the message Configuration system failed to initialize, I'm just try to get all data from Web APIs using windows form.
Any help could be appreciated.
this the code behind
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Web.Script.Serialization;
- using System.Net.Http;
- using System.Net.Http.Formatting;
- using System.Net;
- namespace WinFormConsumeRestfulApi
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- using (HttpClient _Client = new HttpClient())
- {
- _Client.BaseAddress = new Uri("http://localhost:1028/RestfullApis/");
- HttpResponseMessage respon = _Client.GetAsync("api/peminjamanBuku").Result;
- var pinjamBuku = respon.Content.ReadAsAsync<IEnumerable<tbl_peminjaman>>().Result;
- dataGridView1.DataSource = pinjamBuku;
- }
- }
- }
- }
this the web api Controller - using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- namespace Restfull_Apis.Controllers
- {
- public class PeminjamanBukuController : ApiController
- {
- [HttpPost]
- public IEnumerable<tbl_peminjaman> Get()
- {
- using (perpustakaanEntities entity = new perpustakaanEntities())
- {
- return entity.tbl_peminjaman.ToList();
- }
- }
- public tbl_peminjaman Get(int id)
- {
- using (perpustakaanEntities entity = new perpustakaanEntities())
- {
- return entity.tbl_peminjaman.FirstOrDefault(p => p.id_peminjaman == id);
- }
- }
- public void Post([FromBody] tbl_peminjaman _PinjamBuku)
- {
- using (perpustakaanEntities entity = new perpustakaanEntities())
- {
- entity.tbl_peminjaman.Add(_PinjamBuku);
- entity.SaveChanges();
- }
- }
- public void Put(int id, [FromBody] tbl_peminjaman Pinjam)
- {
- using (perpustakaanEntities entity = new perpustakaanEntities())
- {
- var _entity = entity.tbl_peminjaman.FirstOrDefault(p => p.id_peminjaman == id);
- _entity.tanggal_pinjam = Pinjam.tanggal_pinjam;
- _entity.tanggal_kembali = Pinjam.tanggal_kembali;
- _entity.id_buku = Pinjam.id_buku;
- _entity.id_anggota = Pinjam.id_anggota;
- _entity.id_petugas = Pinjam.id_petugas;
- entity.SaveChanges();
- }
- }
- public void Delete(int id)
- {
- using (perpustakaanEntities entity = new perpustakaanEntities())
- {
- entity.tbl_peminjaman.Remove(entity.tbl_peminjaman.FirstOrDefault(p => p.id_peminjaman == id));
- entity.SaveChanges();
- }
- }
- }
- }
