HttpClient PostAsync 模型为 null

2024-01-06

我试图将 TalimatGorevModelmobile 模型发布到 TalimatGorevEkleService() 方法,但每次 talimatGorevPost = null.for 后处理:

我使用了 WebInvoke,但在 TalimatGorevEkleService 方法 talimatGorevModelmobil 返回 null

 [OperationContract]
        [WebInvoke(Method = "POST",UriTemplate = "/TalimatGorevEkleService", BodyStyle = WebMessageBodyStyle.Wrapped)]
        //int TalimatGorevEkleService( string talimat, string talimatGorev, DateTime sonTarih, int[] list, string token );
        string TalimatGorevEkleService(TalimatGorevModelmobil talimatGorevModelmobil);

TalimatGorevEkle.xaml.cs:

 public void GorevEkle(object sender, EventArgs e)
            {
                //var deneme = OnCollectionViewSelectionChanged();
                TalimatGorevModelmobil talimatGorevPost = new TalimatGorevModelmobil();
                //var jsonValue = JsonConvert.SerializeObject(kullaniciList);
                talimatGorevPost.GorevliListe = kullaniciList;
                talimatGorevPost.TalimatBaslik = talimatAdi.Text;
                talimatGorevPost.TalimatGorevAdi = talimatGörevAdi.Text;
                talimatGorevPost.SonTarih = gorevSonTarih.Date;
                string durum = Methodlar.TalimatGorevEkleAsync(talimatGorevPost, Sabitler.Token).Result;
                if (!string.IsNullOrEmpty(durum))
                {
                    var a = new NotificationOptions() { Title = "Uyarı", Description = durum, IsClickable = false, AllowTapInNotificationCenter = true, ClearFromHistory = true };
    
                    App.notificator.Notify(a);
                }
                else
                {
                    var a = new NotificationOptions() { Title = "Bilgilendirme", Description = "Gorev kayıt edilmiştir.", IsClickable = false, AllowTapInNotificationCenter = true, ClearFromHistory = true };
                    App.notificator.Notify(a);  
                }
            }

Methodlar.cs:

 public static async Task<string> TalimatGorevEkleAsync( TalimatGorevModelmobil talimatGorevPost, string token)
        {
            var client = new HttpClient();
            var json = JsonConvert.SerializeObject(talimatGorevPost);

            var stringContent = new StringContent(json, Encoding.UTF8 ,"application/json");
            //var json = JsonConvert.SerializeObject(talimatGorevPost);
            //string url = Sabitler.Service_Url + "/TalimatGorevEkleService?talimat=" + talimat + "&talimatGorev=" + talimatgorev + "&sonTarih=" + sonTarih + "&list=" + list + "&token=" + token;
            //string url = Sabitler.Service_Url + "/TalimatGorevEkleService?talimatGorevPost=" + talimatGorevPost + "&token=" + token;
            var url = await client.PostAsync(Sabitler.Service_Url + "/TalimatGorevEkleService", stringContent);
          
            var responseString = await url.Content.ReadAsStringAsync();
           
                return responseString;

        }

Service:

 public int TalimatGorevEkleService(TalimatGorevModelmobil talimatGorevPost)
        {
            TalepTakipDBEntities db = new TalepTakipDBEntities();
            //KullaniciToken kt = KulListe.FirstOrDefault(l => l.Token == token);
            //if (kt == null)
            //    return (int)Sabit.SistemDurumlar.TokenSureDoldu;

            tbl_Talimat newTalimat = new tbl_Talimat();
            newTalimat.Baslik = talimatGorevPost.TalimatBaslik;
            if (newTalimat.ID == 0)
            {
               // newTalimat.IslemKulID = kt.ID;
                newTalimat.isGenel = true;
                //talimat.GrupID = kt.GrupID.Value;
                newTalimat.EklenmeTarihi = DateTime.Now;
                db.tbl_Talimat.Add(newTalimat);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Fonksiyonlar.HataEkle(ex);
                
                //return Redirect(Request.UrlReferrer.AbsoluteUri);
            }


            tbl_TalimatGorev grv = new tbl_TalimatGorev();
            grv.SonTarih = talimatGorevPost.SonTarih;
            grv.Baslik = talimatGorevPost.TalimatGorevAdi;
            if (grv.ID == 0)
            {
                //grv.IslemKulID = kt.ID;
                grv.EklenmeTarihi = DateTime.Now;
                grv.DurumID = (int)Sabitler.TalimatSurecTur.Bekliyor;
                grv.TalimatID = newTalimat.ID;
                db.tbl_TalimatGorev.Add(grv);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Fonksiyonlar.HataEkle(ex);

            }
            if (talimatGorevPost.GorevliListe != null && talimatGorevPost.GorevliListe.Any())
            {
                tbl_TalimatGorevSurec src = new tbl_TalimatGorevSurec();
                //src = YeniSurecEkle(grv, "", (int)Sabitler.TalimatSurecTur.Yonlendirme, kullaniciList);
            }

            return (int)Sabit.SistemDurumlar.Olumlu;
        }

talimatGorevPost = null


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HttpClient PostAsync 模型为 null 的相关文章

随机推荐