Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在列表框窗口窗体中使用c#输出调用Web服务_C#_Web Services_Listbox - Fatal编程技术网

在列表框窗口窗体中使用c#输出调用Web服务

在列表框窗口窗体中使用c#输出调用Web服务,c#,web-services,listbox,C#,Web Services,Listbox,我觉得自己是个白痴,不得不问这个问题,但我正在努力将web服务调用中的数字输出到我的列表框中。我的列表框中写着“Task2.wsCall.Service1SoapClient”。正如我所期望的那样,在1、2、3等方面,web服务只包含以下内容: [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Component

我觉得自己是个白痴,不得不问这个问题,但我正在努力将web服务调用中的数字输出到我的列表框中。我的列表框中写着“Task2.wsCall.Service1SoapClient”。正如我所期望的那样,在1、2、3等方面,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.");
        }
    }
}
公共部分类表单1:表单
{
公共表格1()
{
初始化组件();
}
private void b按下鼠标单击(对象发送者,事件参数e)
{
尝试
{
对于(int i=1;i<21;i++)
{
wsCall.Service1SoapClient CallWebService=新建wsCall.Service1SoapClient();
lstBox.Items.Add(CallWebService);
//第1栏.项目.添加(i);
}
}
捕获(例外)
{
Show(“捕获异常”);
}
}
}

您似乎尚未调用该方法。请尝试以下操作:

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

        lstBox.Items.Add(CallWebService.getNumber(i));
      }
for(int i=1;i<21;i++)
{
wsCall.Service1SoapClient CallWebService=新建wsCall.Service1SoapClient();
lstBox.Items.Add(CallWebService.getNumber(i));
}
像这样更改了代码

  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.");
            }
        }
    }
公共部分类表单1:表单
{
公共表格1()
{
初始化组件();
}
private void b按下鼠标单击(对象发送者,事件参数e)
{
尝试
{
对于(int i=1;i<21;i++)
{
wsCall.Service1SoapClient CallWebService=新建wsCall.Service1SoapClient();
添加(CallWebService.getNumber(i.toString());
//像这样更改代码
//第1栏.项目.添加(i);
}
}
捕获(例外)
{
Show(“捕获异常”);
}
}
}