2015-06-23 55 views
1

我被給了一個QAAWS,我需要從中提取數據。對於隱私問題,我不能給你QAAWS,但它與this一樣。使用Visual Studio 2010消費QAAWS

我添加了wsdl作爲服務參考,但我不知道如何獲取數據,因爲我必須輸入登錄名和密碼。我可以使用SOAPUI並獲取我可以使用的XML文件,但是我希望使我的網站使用QAAWS的過程更加自動化。

我還沒有找到任何好的教程或指南的運氣。有人曾經處理過這些服務嗎?

回答

1

你可以做到以下幾點:

  1. 在Visual Studio 10創建一個新的控制檯應用程序
  2. 下一頁添加Web引用,並使用提供給您的Web服務的WSDL URL。
  3. program.cs文件中寫入以下代碼(TestWeb這裏是你的Web引用的名稱):

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using 
    ConsoleApplication1.TestWeb; 
    namespace ConsoleApplication1 
        { 
        class Program 
         { 
         static void Main(string[] args) 
          { 
          ConsoleApplication1.TestWeb.TestService test1 = new 
          ConsoleApplication1.TestWeb.TestService(); 
          String message, creatorname, creationdateformatted, description, universe; 
          DateTime creationdate; 
          int queryruntime, fetchedrows; 
          ConsoleApplication1.TestWeb.Row[] row = test1.runQueryAsAService("<cms username>", "<password>", out message, out creatorname, out creationdate, out creationdateformatted, out description, out universe, out queryruntime , out fetchedrows); 
          int resultCount = row.Length; 
          Console.WriteLine("Message = " + message); 
          Console.WriteLine("Creator Name = " + creatorname); 
          Console.WriteLine("Creation Date = " + creationdate.ToString()); 
          Console.WriteLine("Creation Date Formatted = " + creationdateformatted); 
          Console.WriteLine("Description = " + description); 
          Console.WriteLine("Universe = " + universe); 
          Console.WriteLine("Query Run Time = " + queryruntime); 
          Console.WriteLine("Fetched Rows = " + fetchedrows); 
          for (int i = 0; i < resultCount; i++) 
           { 
           Console.WriteLine(row[i].ShipperID + " " + row[i].CompanyName + " " + row[i].Phone); 
           } 
          Console.Read(); 
          } 
         } 
        } 
    

usernamepassword可以寫入的代碼,如果你想。這是最初從這page。我測試了它與我自己的Web服務並且它工作。