1

我觉得不得不问这个问题是个白痴,但我正在努力将网络服务调用中的数字输出到我的列表框。它只是返回写在我的列表框中的“Task2.wsCall.Service1SoapClient”。正如我所期望的那样,Web 服务内部只有以下内容:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public int getNumber(int n)
    {
        return n * n * 100;
    }
}

所以,我可能做错了。感谢任何提供帮助的人,这是我的代码:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void btnPress_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 1; i < 21; i++)
            {
             wsCall.Service1SoapClient CallWebService = new wsCall.Service1SoapClient();
             lstBox.Items.Add(CallWebService);

                //lstBox.Items.Add(i);

            }
        }
        catch (Exception)
        {
            MessageBox.Show("Exception caught.");
        }
    }
}
4

2 回答 2

0

看来您还没有调用该方法。试试这个:

for (int i = 1; i < 21; i++)
      {
        wsCall.Service1SoapClient CallWebService = new wsCall.Service1SoapClient();

        lstBox.Items.Add(CallWebService.getNumber(i));
      }
于 2012-10-29T12:19:41.490 回答
0

改成这样的代码

  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnPress_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 1; i < 21; i++)
                {
                 wsCall.Service1SoapClient CallWebService = new wsCall.Service1SoapClient();
                 lstBox.Items.Add(CallWebService.getNumber(i).toString());


// Changed Code Like this


                    //lstBox.Items.Add(i);

                }
            }
            catch (Exception)
            {
                MessageBox.Show("Exception caught.");
            }
        }
    }
于 2012-11-29T12:44:14.577 回答