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);

    运行成功

  • 相关阅读:
    git
    代理上网时git不能直接连接远程库的解决办法
    Python程序练习2--模拟三级菜单
    python os模块常用文件操作方法
    Python程序练习1-模拟用户登录验证
    牛牛牛图片胡乱下载
    oozie 4.1.0与4.2.0版本问题BUG
    hbase 协处理器,实现group by,distinct函数
    Js公共操作类 之 String 扩展方法介绍(一)
    CSS3之伪元素选择器和伪类选择器
  • 原文地址:https://www.cnblogs.com/enjoyprogram/p/3289457.html
Copyright © 2011-2022 走看看