पर एक सूची
<int
>
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'
मुझे यकीन है कि यह कुछ आसान है और मैं Daft लगता है जब किसी को यह बताते हैं जाएगा हूँ:)
चीयर्स कार्ल
मैं बस अपनी वेब विधि बदल दूंगा :-) int []। यह शायद अन्य वेब सेवा उपभोक्ताओं के जीवन को आसान बना देगा। – Robert
मुझे पसंद है लेकिन जैसा कि यह coursework के लिए है, वे निर्दिष्ट करते हैं कि: एक नई एएसपीएक्स एसओएपी वेब सेवा (जैसा यूनिट 1 में चर्चा की गई है) बनाएं जो पूर्णांक के एक सूची की गणना की गणना करेगा और परिणाम लौटाएगा। मुझे नहीं पता कि अगर इसे वेब सेवा में 'int []' के रूप में पास करना संभव होगा, तो योग करने के लिए 'सूची ' में कनवर्ट करें, फिर 'int' को वापस करें, इस प्रकार विनिर्देश के साथ? –
Carl