0

私は 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;
    }
}

私の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();
}

で試してみました!

4

1 に答える 1

0

WCF Web サービスでは、プリミティブ型のみを転送できます。リストを配列に変更して、もう一度試してください。

于 2015-09-07T09:31:21.763 に答える