.NET SOAP Example

Overview

The .NET SDK includes an executable that can automatically generate the files necessary to access screen-scraper's SOAP interface as an object.

The first step in the process is getting screen-scraper running as a server.

Next we will generate the service class to do the actual communication in SOAP for us. There is a wsdl.exe in the Bin directory of the .NET SDK. Find it on your computer. Using v1.1 type this command:

"C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\wsdl.exe" http://localhost:8779/axis/services/SOAPInterface?wsdl

To see the options available when using wsdl.exe like the output language being Visual Basic, try the flag /?.

After creating the SOAPInterfaceService class, it is possible that there is a mistake in the code. Find the getDataSet method. If the method returns String[], then change it to String[][] and also the casting of the returned object.

C# Code Example

The following is an example class which uses the generated class from above to call on the scraping session created in Tutorial 2.

Be sure that the newly created class is part of the compilation process.

using System;
using System.Threading;

/*
 * This class calls screen-scraper through SOAP to run Tutorial 2's
 * scraping session and return the results.
 */

public class Tutorial2
{
    public static void Main()
    {
        // This is the object used to call the remote API.
        SOAPInterfaceService soap = new SOAPInterfaceService();

        // First, initialze the scraping session and remember
        // the ID returned.
        string id = soap.initializeScrapingSession("Shopping Site");

        // Set the initial variables before running.
        soap.setVariable(id, "SEARCH", "dvd");
        soap.setVariable(id, "PAGE", "1");

        // Start the scrape, this method returns immediately,
        // though the scraping has not completed.
        soap.scrape(id);

        // One way to do things is to wait until the scraping
        // session completes.
        while (soap.isFinished(id) != 1)
        {
            Thread.Sleep(1000);
        }

        // Get the data set to all the products scraped.
        string[][] dataSet = soap.getDataSet(id, "PRODUCTS");

        // Returned the used memory for storing session
         // variables to the virtual machine.
        soap.removeCompletedScrapingSession(id);

        // Loop through all the data records.
        foreach (string[] datarecord in dataSet)
        {
            // Loop through all the key, value pairs.
            foreach (string record in datarecord)
            {
                Console.Write(record);
                Console.Write("\t");
            }
            Console.WriteLine();
        }
    }
}