我遇到的问题是,我创建了一个Web服务和一个Windows表单(分别作为不同的解决方案)。我使用服务引用将Web服务添加到表单应用程序中。我可以毫无问题地向Web服务传递“int”或“string”,但我无法传递整数数组或List<int>。
以下是Web服务代码:
我收到的错误信息是:
参数 '1': 无法从 'System.Collections.Generic.List' 转换为 'CalculateForm.CalculateService.ArrayOfInt'
我相信这是一个简单的问题,当有人指出来时,我会感到很傻 :)
谢谢 卡尔
以下是Web服务代码:
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Services;
namespace CalculateService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int CalcluateSum(List<int> listInt)
{
int sum = listInt.Sum();
return sum;
}
}
}
客户端代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CalculateForm
{
public partial class FormCalculate : Form
{
List<int> intArray = new List<int>();
public FormCalculate()
{
InitializeComponent();
}
private void btnAddNum_Click(object sender, EventArgs e)
{
intArray.Add(Convert.ToInt32(txtAddNum.Text));
txtAddNum.Clear();
listBoxAddNum.Items.Clear();
for (int i = 0; i < intArray.Count; i++)
{
listBoxAddNum.Items.Add(intArray[i]);
}
}
private void btnCalculate_Click(object sender, EventArgs e)
{
CalculateForm.CalculateService.Service1SoapClient client = new CalculateForm.CalculateService.Service1SoapClient();
int result = client.CalcluateSum(intArray);
txtResult.Text = Convert.ToString(result);
}
}
}
我收到的错误信息是:
参数 '1': 无法从 'System.Collections.Generic.List' 转换为 'CalculateForm.CalculateService.ArrayOfInt'
我相信这是一个简单的问题,当有人指出来时,我会感到很傻 :)
谢谢 卡尔