2012-03-07 65 views
0

不知道會不會有人能夠理解這一點,但這裏是代碼:webservice在控制檯應用程序中計算總和?

 case 1: 
     double[] myArrai1 = new double[3]; 
     Console.ForegroundColor = ConsoleColor.Yellow; 
     Console.BackgroundColor = ConsoleColor.DarkGray; 
     Console.WriteLine("*-------------------------------------------------------* "); 
     Console.WriteLine("* Enter an array of numbers to get the sum total  * "); 
     Console.WriteLine("*-------------------------------------------------------* "); 
     Console.WriteLine("Insert a number"); 
     myArrai1[0] = double.Parse(Console.ReadLine()); 
     Console.WriteLine("Insert a number"); 
     myArrai1[1] = double.Parse(Console.ReadLine()); 
     Console.WriteLine("Insert a number"); 
     myArrai1[2] = double.Parse(Console.ReadLine()); 
     DrawStarLine(); 
     foreach (double d in myArrai1) 
     Console.WriteLine(d); 
     Webservices09004961.ServiceReference1.CalculateSumRequest array = new ServiceReference1.CalculateSumRequest(); 
     //ServiceReference1.CalculateSumRequest array = new ServiceReference1.CalculateSumRequest(); 
     Webservices09004961.ServiceReference1.ArrayOfDouble arrayOfDoubles = new Webservices09004961.ServiceReference1.ArrayOfDouble(); 
     //CalculateSumOfList.ServiceReference1.Service1SoapClient client = new CalculateSumOfList.ServiceReference1.Service1SoapClient(); 
     //CalculateSumOfList.ServiceReference1.ArrayOfDouble arrayOfDoubles = new CalculateSumOfList.ServiceReference1.ArrayOfDouble(); 
     arrayOfDoubles.AddRange(myArrai1); 
     double e = array.CalculateSum(arrayOfDoubles); //error on this line CalculateSum? 
     Console.WriteLine("=" + e); 
     Console.ReadLine(); 
     break; 

我存儲在myArrai1 3個用戶輸入的數字,我想「和」來概括我已經做了Web引用CalculateSumOfList。

但它說我的webreference不包含在我的web服務中的CalculateSum,但它確實和即時在相同的生成/項目中使用它的Windows窗體?

謝謝。

+0

你得到了什麼錯誤? – 2012-03-07 19:00:26

+0

這是非常有意義的(至少對我來說,因爲我沒有不同的東西) - 但爲了幫助我們需要知道錯誤是什麼...... – Murph 2012-03-07 19:01:10

+0

命名空間錯誤,缺少指令。代碼來自Windows窗體應用程序,但我不知道如何調用並創建一個帶有webreference的雙精度數組? – 2012-03-07 19:02:12

回答

1

因此,通過一些試驗和錯誤,我意識到我第一次調用客戶端時已經用於其他web服務。

case 1: 
     double[] myArrai1 = new double[3]; 
     Console.ForegroundColor = ConsoleColor.Yellow; 
     Console.BackgroundColor = ConsoleColor.DarkGray; 
     Console.WriteLine("*-------------------------------------------------------* "); 
     Console.WriteLine("* Enter an array of numbers to get the sum total  * "); 
     Console.WriteLine("*-------------------------------------------------------* "); 
     Console.WriteLine("Insert a number"); 
     myArrai1[0] = double.Parse(Console.ReadLine()); 
     Console.WriteLine("Insert a number"); 
     myArrai1[1] = double.Parse(Console.ReadLine()); 
     Console.WriteLine("Insert a number"); 
     myArrai1[2] = double.Parse(Console.ReadLine()); 
     DrawStarLine(); 
     foreach (double d in myArrai1) 
     Console.WriteLine(d); 
     Webservices09004961.ServiceReference1.Service1SoapClient client2 = new ServiceReference1.Service1SoapClient(); 
     Webservices09004961.ServiceReference1.ArrayOfDouble arrayOfDoubles = new Webservices09004961.ServiceReference1.ArrayOfDouble(); 
     arrayOfDoubles.AddRange(myArrai1); 
     string e = client2.CalculateSum(arrayOfDoubles); 
     Console.WriteLine("=" + e); 
     Console.ReadLine(); 
     break; 

所以總結起來(沒有雙關語意)我可以花了5小時看,閱讀教程或只是用來試錯的升技與SO的幫助!

相關問題