将对象添加到列表时出现重载错误

时间:2015-11-26 06:19:39

标签: c# .net list web-services wcf

我编写了一个Web服务和构造函数,它将对象添加到我的列表中。我收到一个对我没有意义的错误,因为我传递了我应该传递的3个参数。

错误是:

  

没有任何论据符合所要求的形式   参数' myArticleID'的   ' MainPage.GetTileDetails.GetTileDetails(string,string,int)'

这是我的代码:

网络服务:

[OperationContract]
List<ViewDetails> ViewDetails();

[DataContract]
public class ViewDetails
{
    [DataMember]
    public string TitleView { get; set; }

    [DataMember]
    public string BodyView { get; set; }

    [DataMember]
    public int ArticleID { get; set; }

    public ViewDetails() { }
    public ViewDetails(string myTitleView, string myBodyView, int myArticleID)
    {
        this.TitleView = myTitleView;
        this.BodyView = myBodyView;
        this.ArticleID = myArticleID;
    }
}

我使用网络服务的项目

 public async void ViewData()
    {
        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
        List<GetTileDetails> tileList = new List<GetTileDetails>();

        var res = await client.ViewDetailsAsync();
        for (int i = 0; i < res.Count; i++)
        {
            tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ..."), res[i].ArticleID);
        }
        tileGridView.ItemsSource = tileList;
    }

public class GetTileDetails
    {
        public string TitleView { get; set; }
        public string BodyView { get; set; }
        public int ArticleID { get; set; }

        public GetTileDetails() { }
        public GetTileDetails(string myTitleView, string myBodyView, int myArticleID)
        {
            this.TitleView = myTitleView;
            this.BodyView = myBodyView;
            this.ArticleID = myArticleID;
        }
    }

谁能告诉我为什么会收到这个错误?我传入(string,string,int)....

1 个答案:

答案 0 :(得分:1)

替换此行:

tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ..."), res[i].ArticleID);

这一个:

tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ...", res[i].ArticleID));

请注意,您在)之后放错" ...")