Am new to MVC (web dev) so please patience. I am working on building a simple app that will require a user to input some basic data, then the app will send that info to a WCF service that will perform some operation and then display the results in a table.
So far, here is what I have been able to come up with
//MODEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyApp.Models
{
public class UT
{
public int ID { get; set; }
public string Name { get; set; }
}
public class GetUT
{
public int UTID { get; set; }
public double AccountNumb { get; set; }
public double ZipCode { get; set; }
public List<UT> utls { get; set; }
public GetUT()
{
UTID = 0;
}
}
}
//CONTROLLER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyApp.Models;
namespace MyApp.Controllers
{
public class DataInputController : Controller
{
//
// GET: /DataInput/
public ActionResult Index()
{
return View();
}
public ActionResult EnterInfo()
{
GetUT getUT = new GetUT();
getUT.utls = GetOptions();
return View(getUT);
}
private List<UT> GetOptions()
{
List<UT> utls = new List<UT>();
utls.Add(new UT() { ID = 1, Name = "1st UT" });
utls.Add(new UT() { ID = 2, Name = "2nd UT" });
utls.Add(new UT() { ID = 3, Name = "3rd UT" });
utls.Add(new UT() { ID = 4, Name = "4th UT" });
return utls;
}
}
}
//VIEW
@using MyApp.Models
@using MyApp.Controllers
@model GetUT
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>EnterInfo</title>
</head>
<body>
<div>
@Html.DropDownListFor(x => x.UTID, new SelectList(Model.utls, "ID", "Name", Model.UTID))<br />
Enter Account# : <input type="text" name="AccountNumb" /><br />
Enter ZipCode : <input type="text" name="Zipcode" /><br /><br />
<input type="submit" value="Submit Info" />
</div>
</body>
</html>
How do I get this to consume a WCF service and then display the output in a table? I can't manage to make head way with that part of this. I would greatly appreciate any help with this.
In your project add the service as reference by "Add Service Reference", it will create a proxy class in your project. then you can use that inside your controller to call the service.
Additionally you can follow the Facade Pattern and create a service layer between your controller and WCF Proxy.
mohaminho
Member
9 Points
44 Posts
How do I consume a WCF service and display output?
Dec 30, 2012 09:15 PM|LINK
Am new to MVC (web dev) so please patience. I am working on building a simple app that will require a user to input some basic data, then the app will send that info to a WCF service that will perform some operation and then display the results in a table.
So far, here is what I have been able to come up with
//MODEL using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MyApp.Models { public class UT { public int ID { get; set; } public string Name { get; set; } } public class GetUT { public int UTID { get; set; } public double AccountNumb { get; set; } public double ZipCode { get; set; } public List<UT> utls { get; set; } public GetUT() { UTID = 0; } } } //CONTROLLER using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MyApp.Models; namespace MyApp.Controllers { public class DataInputController : Controller { // // GET: /DataInput/ public ActionResult Index() { return View(); } public ActionResult EnterInfo() { GetUT getUT = new GetUT(); getUT.utls = GetOptions(); return View(getUT); } private List<UT> GetOptions() { List<UT> utls = new List<UT>(); utls.Add(new UT() { ID = 1, Name = "1st UT" }); utls.Add(new UT() { ID = 2, Name = "2nd UT" }); utls.Add(new UT() { ID = 3, Name = "3rd UT" }); utls.Add(new UT() { ID = 4, Name = "4th UT" }); return utls; } } } //VIEW @using MyApp.Models @using MyApp.Controllers @model GetUT @{ Layout = null; } <!DOCTYPE html> <html> <head> <title>EnterInfo</title> </head> <body> <div> @Html.DropDownListFor(x => x.UTID, new SelectList(Model.utls, "ID", "Name", Model.UTID))<br /> Enter Account# : <input type="text" name="AccountNumb" /><br /> Enter ZipCode : <input type="text" name="Zipcode" /><br /><br /> <input type="submit" value="Submit Info" /> </div> </body> </html>How do I get this to consume a WCF service and then display the output in a table? I can't manage to make head way with that part of this. I would greatly appreciate any help with this.
Gaspard
Contributor
2066 Points
416 Posts
Re: How do I consume a WCF service and display output?
Dec 30, 2012 10:54 PM|LINK
This thread may help
http://stackoverflow.com/questions/8937508/tutorial-on-consuming-wcf-4-0-with-asp-net-in-vs2010
Regards
CPrakash82
All-Star
18290 Points
2844 Posts
Re: How do I consume a WCF service and display output?
Dec 30, 2012 10:58 PM|LINK
In your project add the service as reference by "Add Service Reference", it will create a proxy class in your project. then you can use that inside your controller to call the service.
Additionally you can follow the Facade Pattern and create a service layer between your controller and WCF Proxy.