将generic.list转换为ArrayOfInt以通过SOAP传输到Web服务 [英] Converting generic.list to ArrayOfInt for transmission over SOAP to web service
问题描述
当我尝试传递列表时,我试图将一个通用的整数列表从客户端应用程序传递到Web服务。作为Web服务中声明的Web方法的一个参数,我得到错误无法从generic.list转换为ArrayOfInt。
I'm attempting to pass a generic list of integers from a client application to a web service using the the SOAP protocol.
如何解决这个问题?
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();
}
错误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
Error 1 The best overloaded method match for 'WFCalculate.WSCalculate.CalculateSoapClient.CalculateListSum(WFCalculate.WSCalculate.ArrayOfInt)' has some invalid arguments WFCalculate\Form1.cs 58 27 WFCalculate
推荐答案
//sackoverflow.com/questions/2347530/how-to-pass-a-listint-to-a-service-reference-c-vs2008/2353278#2353278\"> post 因为我认为我们完全一样问题......(可能是相同的课程大声笑),我设法解决它
Hey Abs, thought you might like to check out my post as I think we have exactly the same problem...(probably the same coursework lol) and I managed to solve it
这篇关于将generic.list转换为ArrayOfInt以通过SOAP传输到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!