这可能是一个非常基本的问题,但我还没弄清楚如何在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();
}
}
}
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;
}
}
}
添加服务引用后:
错误是ServiceReference1.Service1 srv = new ServiceReference1.Service1();不存在。
由于
答案 0 :(得分:7)
请试试这个,
希望它会起作用, 感谢。