【问题标题】:List<class> Method exposing WCF service in MVC 4List<class> 方法在 MVC 4 中公开 WCF 服务
【发布时间】:2013-05-28 12:48:23
【问题描述】:

我正在研究 MVC 4 和 WCF 类库,我添加了返回列表的方法,并添加了 WCF 服务的引用。 现在我正在创建 ServiceReference1 的代理,然后我无法获取此 ServiceReference1 对象。 如果我将返回类型更改为字符串,那么它可以工作..

我曾尝试更改所有集合类型,但我无法获得 ServiceReference1 对象。!

我错在哪里或解决方案是什么。?

我的 WCF 代码在这里

public class BuildTrackerService : IBuildTrackerService
{
    public List<Property> DoWork()
    {
        DataTable dt = new DataTable();
        List<Property> objProperty = new List<Property>();
        SqlConnection conn = DbConnection.GetConnection();
        SqlDataAdapter adpt = new SqlDataAdapter("[GetPropertyDetail]", conn);
        adpt.SelectCommand.CommandType = CommandType.StoredProcedure;
        try
        {
            conn.Open();
            adpt.Fill(dt);
        }
        catch (Exception) { throw; }
        finally
        {
            conn.Close();
            adpt.Dispose();
        }
        objProperty = DataTableHelper.ConvertTo<Property>(dt);
        return objProperty;
    }
}

MY MVC 4 ActionResult 就像

public ActionResult Index()
{
    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

    /*
        ==> this ServiceReference1 is not accessible here....!
        var obj = new ServiceReference1.BuildTrackerServiceClient();
    */

    var objct = obj.DoWork();
    return View();
}

我试过了!

【问题讨论】:

  • 请发布您的代码。
  • 您能否提供更多细节。因为我已经尝试过我的解决方案并且它没有给我这样的错误或问题。所以请如果你可以发布代码,这将有助于我纠正它。
  • 我已经修改了描述请看...!

标签: wcf asp.net-mvc-4


【解决方案1】:

使用 WCF Web 服务,您只能传输原始类型。将您的列表更改为数组,然后重试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多