Search code examples
asp.netweb-servicesvisual-studio-2010wsdl

Consume a QAAWS with Visual Studio 2010


I been given a QAAWS and I need to pull out the data from it. For privacy issues I cannot give you the QAAWS but it is the same as this one.

I added the wsdl as a service reference, but I am not sure how to get the data since I have to enter the login and password. I can use SOAPUI and obtain an XML file that I can use but I want to make the process more automatic where I use the QAAWS with my website.

I haven't had any luck searching any good tutorials or guides. Has anyone dealt with these services before?


Solution

  • You can do the following:

    1. In Visual Studio 10 create a new Console Application
    2. Next add a web reference and use the web service WSDL URL given to you.
    3. On the program.cs file write the following code (TestWeb here is the name of your Web Reference.):

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

    The username and the password can be written into the code if you want. This is originally from this page. I tested it against my own Web Service and it worked.