我试图将使用SOAP协议的客户端应用程序的整数通用列表传递给Web服务。将generic.list转换为ArrayOfInt以通过SOAP传输到Web服务
当我尝试将列表作为参数传递给Web服务中声明的Web方法时,出现错误“无法从generic.list转换为ArrayOfInt”。
我该如何着手解决这个问题?
// web service method
[WebMethod(CacheDuration = 30, Description = "Returns the calculated sum value of all numbers supplied in the list")]
public int CalculateListSum(int[] list)
{
int _sum = 0;
foreach (int _val in list)
{
_sum += _val;
}
return _sum;
}
// client app buton click event
private void btnRun_Click(object sender, EventArgs e)
{
string str = this.tbValues.Text;
// clear the list
ClearIntList();
// take the textbox input, format and add to the List
PopulateIntList(str);
WSCalculate.CalculateSoapClient client = new WSCalculate.CalculateSoapClient();
int[] _int_array = this._int_list.ToArray();
// the line below is generating the error
int _result = client.CalculateListSum(_int_array);
this.tbResult.Text = _result.ToString();
}
错误1最好重载方法 匹配 'WFCalculate.WSCalculate.CalculateSoapClient.CalculateListSum(WFCalculate.WSCalculate.ArrayOfInt)' 有一些无效 参数WFCalculate \ Form1.cs中58 27 WFCalculate
错误2参数 '1':不能转换 从 'INT []' 到 'WFCalculate.WSCalculate.ArrayOfInt' WFCalculate \ Form1.cs中58 51 WFCalculate
只是一个评论。 IList接口不具有在列表类中实现的ToArray方法。如果您使用的是框架3.5,您也可以使用每个IEnumerable 实例中的ToArray扩展方法。 –
Fede
2010-02-25 15:02:32
而不是将列表转换为数组,是否有可能序列化列表传输? – Unflux 2010-02-25 15:10:21
@Abs - 你将不得不编写自己的序列化来做到这一点。同样,为什么要发明轮子,那么SOAP是如何收集的呢? – Oded 2010-02-25 15:38:34