将字符串列表传递给网络服务

Pass list of strings to webservice

我有这个代码:

List<string> emailsToFollow = new List<string>();
ASMXWebServiceReference.WebServiceSoapClient MyASMXWebServiceClient = new ASMXWebServiceReference.WebServiceSoapClient();
//Add values to List here
//Call the webservice
ASMXWebServiceReference.SendResponse mySendResponse = await MyASMXWebServiceClient.SendAsync("g@gg.gg", emailsToFollow);

在网络服务中,这是我的函数的标题:

public bool Send(string myEmail, string[] emaislToFollow)

问题是我遇到了这个错误:

Error Argument 2: cannot convert from 'System.Collections.Generic.List' to 'App9.ASMXWebServiceReference.ArrayOfString'

为什么?

我终于得到了答案并更新了我的post。嗯,看来这里得做点转换了

ASMXWebServiceReference.ArrayOfString myArray = new ASMXWebServiceReference.ArrayOfString();
myArray.AddRange(emailsToFollow);

似乎在服务之外您必须使用 ArrayOfString class 并将您的集合转换为这种非常特殊的类型。

希望对您有所帮助。

更改发送的签名:

public bool Send(string myEmail, List<string> emaislToFollow)