You can use the SystemService service to retrieve a list of companies that are available in a specific database. The appropriate company name must be used in the URL to access other Web services, and this service allows you to retrieve names of available companies.

The following code example shows how to use the SystemService service to retrieve and print a list of companies.

To use the SystemService service to find companies

  1. In Visual Studio, on the File menu, point to New, and then click Project.

  2. Expand the Visual C# node, and then select Console Application. Enter the name FindingCompanies for the application.

  3. In Solution Explorer, right-click the References node in the project, and then click Add Web Reference.

    NoteNote

    If you are using Visual Studio 2008, then click Add Service Reference instead.

  4. In the Add Web Reference window, type the URL that you used when checking the WSDL, such as http://localhost:7047/DynamicsNAV/WS/Services, and then click Go.

    NoteNote

    In Visual Studio 2008, click the Advanced button, click the Add Web Reference button, type the URL, and then click Go.

  5. When the SystemService service is displayed, click Add Reference. Rename the Web reference name from localhost to SystemService.

  6. On the Program.cs tab, add the following lines of code in bold.

      CopyCode imageCopy Code
    namespace UsingSystemService
    {
    	using SystemService;
    
    	class Program
    	{
    		static void Main(string[] args)
    		{
    			// Create instance of service and set credentials.
    			SystemService.SystemService service = new SystemService.SystemService();
    			service.UseDefaultCredentials = true;
    			// The service URL is set by the proxy with a 
    			// value from the .config file.
    
    			// Load all companies into an array.
    			string[] companies = service.Companies();
    
    			// Run through and print all companies.
    			// Also print company name in encoded form.
    			foreach (string company in companies)
    			{
    				Console.WriteLine(company);
    				Console.WriteLine((Uri.EscapeDataString(company));
    		}
    			Console.ReadLine();
    	}
    }
    }
    
  7. Save and compile the FindingCompanies application.

  8. Press F5 to run the application in debug mode.

See Also