Search This Blog

Friday, November 10, 2017

Consume WCF and REST WCF Services in Console and C#

class Program
    {
        static void Main(string[] args)
        {
            
            string ngoServiceUrl ="https://ngo.com/NGO/ngo_services.svc/GetUserinfoData"
            int oprtype = 3;
            string txtEmp="ngo\\\\shrawan";
            WebRequest req = WebRequest.Create(ngoServiceUrl );
            req.ContentType = "application/json; charset=utf-8";
            req.Method = "POST";
            string da = "{\"userid\":\"" + txtEmp + "\",\"oprtype\":" + oprtype + "}";
            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                streamWriter.Write(da);
                streamWriter.Flush();
            }
            var httpResponse = (HttpWebResponse)req.GetResponse();
            if (httpResponse.StatusCode == HttpStatusCode.OK)
            {
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var responseText = streamReader.ReadToEnd();
                    string[] res=responseText.Split(':');
                    string msg = res[2].Split('}')[0];
                    if (msg.Equals("1"))
                    {
                        Console.WriteLine("Redirect");
                    }


                }
            }


                                        
        }


        }

No comments:

Post a Comment