这些有什么不同?

Ati*_*MVP 0 c# wcf

我在wcf服务中有这样的方法

public string PostAllSurveList(List<Survey> surveyList)
{
    var surveyDbList = ConstructDbServeyList(surveyList);
    foreach (var survey in surveyDbList)
    {
        _db.surveys.Add(survey);
    }
    _db.SaveChanges();
    return "Successfully Saved";
}
Run Code Online (Sandbox Code Playgroud)

当我通过以下方式在C#中调用此方法时,它工作正常

var surveys = new Survey[]{new Survey{ Id = 1, ConsumerName = "atish"},};

string reply = client.PostAllSurveList(surveys);
Run Code Online (Sandbox Code Playgroud)

但不是以下列方式工作

var surveys = new List<Survey>{ new Survey { Id = 1, ConsumerName = "atish"}};

string reply = client.PostAllSurveList(surveys);
Run Code Online (Sandbox Code Playgroud)

得到编译时错误.

我的问题是为什么会这样.

Kna*_*ģis 5

在创建WCF服务引用时,您可以指定将用于集合的类型(独立于在服务器端如何声明它).在您的情况下,生成服务客户端以使用数组而不是列表.

您需要更改该服务引用配置.