无法隐式转换类型' void'到'字符串'网络服务

时间:2018-01-09 12:46:09

标签: c# web-services

我是C#的新人,我无法理解为什么我会收到此错误。这是我的代码:

    public partial class Window : System.Windows.Forms.Form
    {

    WebServ.ItemDimWs con = new WebServ.ItemDimWs();

    decimal length, width, height, weight, rescode;
    string user, article, res;

    public Window()
    {
        InitializeComponent();
    }

    private void Window_Load(object sender, EventArgs e)
    {

    }


    public void btn_send_Click(object sender, EventArgs e)
    {
        length = Convert.ToDecimal(tb_lenght.Text.ToString());
        width = Convert.ToDecimal(tb_width.Text.ToString());
        height = Convert.ToDecimal(tb_height.Text.ToString());
        weight = Convert.ToDecimal(tb_weight.Text.ToString());
        article = tb_article.Text;
        user = tb_user.Text;

        string result = con.setItemDims(article, length, width, height, weight, weight, "EA", "KG", "CM", user, ref rescode, ref res);
        MessageBox.Show(result);
        MessageBox.Show("Resp:" + rescode + res + "!!!");
    }
}

我需要向网络服务发送一些信息并收到答案。

3 个答案:

答案 0 :(得分:2)

WebServ.ItemDimWs.setItemDims不返回任何内容,因此您无法将输出分配给字符串。

所以不要这样做

string result = con.setItemDims(article, length, 
        width, height, weight, weight, "EA", "KG", "CM", 
        user, ref rescode, ref res);

你可以选择

con.setItemDims(article, length, 
        width, height, weight, weight, "EA", "KG", "CM", 
        user, ref rescode, ref res);

答案 1 :(得分:0)

您正在将方法setItemDims的返回值赋给字符串变量,但该方法为void(无返回值)

注意:不确定setItemDims的所有参数是什么,我可以看到您正在传递ref res,这可能是设置的结果。再次,只是从命名约定猜测?

答案 2 :(得分:0)

由于webservice方法没有返回任何内容,因此不能像这样调用它。

string result = con.setItemDims(文章,长度,宽度,身高,体重,体重,“EA”,“KG”,“CM”,用户,参考重新编码,参考资料);

如果您希望输出结果,您可以编写服务,结果将是 out 参数。 (如果您可以访问Web服务代码。)

相关问题