将 generic.list 转换为 ArrayOfInt 以通过 SOAP 传输到 Web 服务
我正在尝试使用 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
I'm attempting to pass a generic list of integers from a client application to a web service using the the SOAP protocol.
When I attempt to pass the list as a parameter to the web method declared in the web service, I get the error "cannot convert from generic.list to ArrayOfInt".
How do I go about resolving this?
// 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();
}
Error 1 The best overloaded method
match for
'WFCalculate.WSCalculate.CalculateSoapClient.CalculateListSum(WFCalculate.WSCalculate.ArrayOfInt)'
has some invalid
arguments WFCalculate\Form1.cs 58 27 WFCalculateError 2 Argument '1': cannot convert
from 'int[]' to
'WFCalculate.WSCalculate.ArrayOfInt' WFCalculate\Form1.cs 58 51 WFCalculate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SOAP 不了解列表和集合,但了解数组。
将整数列表转换为整数数组:
并将其传递给它。
更新:
看起来 Web 服务需要
WFCalculate.WSCalculate.ArrayOfInt
,因此您需要将列表转换为该列表并将其传递。未测试:
SOAP doesn't know about Lists and collections, but understands Arrays.
Convert your list of integers to an array of integers:
And pass this through instead.
Update:
Looks like the webservice is expecting
WFCalculate.WSCalculate.ArrayOfInt
, so you need to convert you list to that and pass that through.Not tested: