winform下調用webservice,傳參List


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

運行成功

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM