zoukankan      html  css  js  c++  java
  • winform下调用webservice,传参List<string>

    用c#做了一个webservice,其中一个接口是public bool AddReturns(List<string> SQLStringList)。

    然后在另一个c#做的winform程序中调用,添加WEB引用,引用为WebReference1,定义传参变量为List<string> allRecorders = new List<string>();但是查看其reference.cs代码,发现原来的public bool AddReturns(List<string> SQLStringList)变为了public bool AddSalesorder(string[] SQLStringList)导致用List<string>定义传参值类型不对,

    方法一:修改reference.cs(缺点:webservice若改变,更新引用后需重新手工修改)

    添加   using System.Collections.Generic;然后手工改为public bool AddSalesorder(List<string> SQLStringList)后可以编译成功,当传的SQLStringList内容为一行时调用webservice运行成功,当内容为两行以上时就提示未知异常。

    后在reference.cs添加
            public class ArrayOfString : System.Collections.Generic.List<string>
            {
            }

    然后在winform调用AddReturns处将参数定义由原来的List<string> allRecorders = new List<string>();
                                   改为 WebReference1.Service.ArrayOfString allRecorders = new JXC_System.WebReference1.Service.ArrayOfString();

    myService.AddRecover(allRecorders, strShopName, strShopPassword)

    重新编译运行allRecorders为多行也成功。

    方法二:修改客户端(优点:不用老修改reference.cs)

    客户端实现:List<string> allRecorders = new List<string>();

    for{int i=0;i<10;i++}

    {

    allRecorders.Add(i.tostring());

    }

    string[] strAllRecorders = allRecorders.ToArray();

    myService.AddRecover(strAllRecorders, strShopName, strShopPassword);

    运行成功

  • 相关阅读:
    SQLite out of order error备忘
    SQLITE_TOOBIG
    Android CursorWindow问题备忘
    SQLite3神奇的UNION、UNION ALL与LIMIT组合
    Android Database(SQLite)参数绑定问题初探
    Android SQLite 加入自定义函数
    修改替换/system/framework/framework.jar后重启手机为何没有效果?
    手动调用NDK编译HelloWorld
    第一篇
    程序题
  • 原文地址:https://www.cnblogs.com/enjoyprogram/p/3289457.html
Copyright © 2011-2022 走看看