CHAPTER 7 USING CUSTOM .NET CODE WITH REPORTS
We are not using a separate method that is contained in our Employee class, which would use a web
service to pull the data we want rather than use an XML file. Let’s take a look at this method from
Employee.cs in our Employee class project. You will see in Listing 7-10 that it is a just a simple call to the
web service that we have built and is included in our project. We provide the web service the employeeID
and visit date, just like we did when we pulled the information from XML, but this time the data is
provided directly from the web service, which we will look at in just a bit.
Listing 7-10: 'etting Cost Values Through a Web Service
public static decimal CostPerVisitWS(string employeeID, DateTime visitDate)
{
EmployeeWS.Employee empWS = new EmployeeWS.Employee();
Decimal empAmt;
empAmt = empWS.GetCost(employeeID, visitDate);
return empAmt;
}
We will do much more with web services in Chapters 8 and 9 if you are not yet familiar with them. It
looks to be a much easier process than when we parsed through the XML file, but the bulk of the work is
actually being done on the web service that has been provided in the solution.
Since the web service, in the solution provided, is already set up to have a dependency on the web
service we don’t need to bother with those to test our new data call. Go ahead and start the debug
process, making sure that the reports project is still set up as the startup project in the solution. You can
set the parameter of ServiceYear to be 2010 and view the report. Once you drill down into a patient, you
will notice that the report processes and refreshes the data. This time the data is being pulled through
the web service, which gets the data from the database instead of from an XML file. We have also
included a sample test application that allows you to call the CostPerVisitXML and CostPerVisitWS
methods of the Employee class using a Windows Forms application. This allows you to exercise the class
and step through the code in the Windows Forms environment, which is easier to test and debug.
Tip Writing a test application is a great way to make sure your custom code is properly performing the
expected functions prior to using the code within your SSRS 2012 report. Not only can you create a custom
Windows Forms application as we did, but with the proper version of Visual Studio 2010, you can create
specialized test code and automated test routines.
Debugging Custom Assemblies
For ease of debugging, the recommended way to design, develop, and test custom assemblies is to
create a solution that contains both your test reports and your custom assembly. This will allow you easy
access to both the report and the code you will use in it at the same time from within Visual Studio.
We’ll now show you how to set up Visual Studio to allow you to debug the Employee assembly you
have just written:
- In the Solution Explorer, right-click the solution, and select Configuration
Manager. This will allow you to set the build and deploy options for debugging.