Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取将json数据发布到wcf rest服务的结果_C#_Json_Rest_Wcf - Fatal编程技术网

C# 获取将json数据发布到wcf rest服务的结果

C# 获取将json数据发布到wcf rest服务的结果,c#,json,rest,wcf,C#,Json,Rest,Wcf,我有休息服务 [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/AddNews", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] bool Add(News entity); 这里是imp: public bool Add(News entity) {

我有休息服务

 [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/AddNews", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        bool Add(News entity);
这里是imp:

  public bool Add(News entity)
        {
            try
            {
                _ctx.News.Add(entity);
                _ctx.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                // TODO log this error
                return false;
            }
        }
我将数据发布到我的服务中,但我需要操作的结果,这里是
bool
。如何在代码中获得结果

   News student = new News
            {
                Id = Guid.NewGuid(),
                Subject = "wfwf",
                ViewerCounter = 1, // removed the "" (string)
                MainContent = "fsdsd", // renamed from "Content"
                SubmitDateTime = DateTime.Now,
                ModifiedDateTime = DateTime.Now,
                PublisherName = "sdaadasd",
                PictureAddress = "adfafsd",
                TypeOfNews = "adsadaad"
            };
            WebClient Proxy1 = new WebClient();
            Proxy1.Headers["Content-type"] = "application/json";
            MemoryStream ms = new MemoryStream();
            DataContractJsonSerializer serializerToUplaod = new DataContractJsonSerializer(typeof(News));
            serializerToUplaod.WriteObject(ms, student);
             Proxy1.UploadData("http://localhost:47026/NewsRepository.svc/AddNews", "POST", ms.ToArray());
只要用这个:

byte[] a=    Proxy1.UploadData("http://localhost:47026/NewsRepository.svc/AddNews", "POST", ms.ToArray());


            string result = System.Text.Encoding.UTF8.GetString(a);