Step 4: Building and Testing the Application
In this step, you will build and test your application. Visual Studio offers several methods to build and run a console application from the IDE, such as:
Start Without Debugging (CTRL + F5)
Start (F5)
Build, Run, and Debug the Application
To build and run the application
On the Debug menu, click Start Without Debugging or press CTRL + F5. This ensures that the console window remains open after the program has finished executing.
The application prints the following output to the console.
Note
These values vary depending on the values you have in your workbook, session ID, and so on.
The Credential is: System.Net.SystemNetworkCredential Total rows in range: 18 Value in range is: 4245.955129
Press any key to close SampleApplication.exe.
File Not Found Exception
If the path to the workbook you provided is wrong, you will get a "file not found" exception, which is caught by the following code:
catch (SoapException e) { Console.WriteLine("SOAP Exception Message: {0}", e.Message); }
The application prints the following SOAP exception output to the console:
SOAP Exception Message: The file you selected could not be found. Check the spelling of the file name and verify that the location is correct.
Index Out Of Range Exception
If you try to get a value from outside the range, you will get a System.IndexOutOfRangeException exception. The application prints the following output to the console:
The Credential is: System.Net.SystemNetworkCredential The sessionID is : 64.28e58e90-b757-4658-b1c4-890ad68ef6cbRmqR4IINXfkMeOJRG8Iq0Y 27tVk=110.33d3R6fqv7tr2jPyYiPwRu|!@en-US|en-US|+0480#0000-10-00-05T02:00:00:0000 #+0000#0000-04-00-01T02:00:00:0000#-0060 Total rows in range: 18
Then you will get an unhandled exception that says:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in SampleApplication.exe Additional information: Index was outside the bounds of the array.
You can handle the above unhandled exception by adding another catch block to catch the exception after the SOAP exception catch block as shown here:
catch (Exception e) { Console.WriteLine("Exception Message: {0}", e.Message); }
To run the application using F5
You can run your application by clicking Start on the Debug menu, or by pressing F5. To ensure that the console window remains open after the program has finished executing, you could add the following line of code at the end of your code (after the catch block):
Console.ReadLine();
Press any key to close SampleApplication.exe.
See Also
Tasks
Step 1: Creating the Web Service Client Project
Step 2: Adding a Web Reference
Step 3: Accessing the Web Service
Walkthrough: Developing a Custom Application Using Excel Web Services
How to: Trust Workbook Locations Using Script