public static string AddWithParameter(NumberService obj) { using (HttpResponseMessage response = new HttpClient().Post(uri,HttpContentExtensions.CreateDataContract(obj))) { int res = response.Content.ReadAsDataContract<int>(); return res.ToString(); } }
static void Main(string[] args) { uri = "http://localhost:3602/RestService.svc/"; // Calling without parameter Console.WriteLine(AddWithoutParameter()); Console.Read(); //Calling with parameter NumberService obj = new NumberService() { Number1 = 7, Number2 = 2 }; Console.WriteLine(AddWithParameter(obj)); Console.Read(); }
public int Add(NumberService n1) { res = Convert.ToInt32(n1.Number1) + Convert.ToInt32(n1.Number2); return res; }