Bon*_*omi 1 c# asp.net-mvc wcf
这可能是一个非常基本的问题,但我还没弄清楚如何在mvc应用程序中调用简单的wcf服务.我添加了服务引用,最后我希望使用服务引用名称来调用它,但在解决方案中我找不到它!我究竟做错了什么?
更新25/09/2014

控制器代码:
namespace MvcApplication4.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
ServiceReference1.Service1 srv = new ServiceReference1.Service1();
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
Run Code Online (Sandbox Code Playgroud)
WCF服务代码:
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
Run Code Online (Sandbox Code Playgroud)
添加服务引用后:

错误是ServiceReference1.Service1 srv = new ServiceReference1.Service1(); 不存在.
谢谢
请试试这个,
希望它会起作用,谢谢.