18 May 2009

ASP.Net as Crystal Reports data source

There are not many good articles on using an ASP.Net web source as a data source.  This post attempts to enumerate the settings and make the process straightforward.

Before starting, I want to make a couple of recommendations:

  • In my experience, embedded schemas do not work.  That means that working with native types (such as DataSets) that have embedded schemas won’t work well.
  • Since embedded schemas don’t work, use a simple XMLDocument object as your return value.
  • You will need to write your own schema for service.  Again – keep the return XML simple.

The instructions for creating an Crystal Reports XML Data Source are as follows*:

  1. Open the database expert.  Choose Create New Connection / XML.
  2. XML (data source) type and location:  Choose enter in your service in the URL HTTP(S) XML URL textbox.  Check the box for Specify Schema File.  Click ‘Next’.  There are a couple of items to note here.
    • Crystal gives an option for choosing Use Web Service Data Source.  I cannot get this to work – don’t choose it.
    • The URL for the service is the .asmx path/service name.  For instance, if your service is getGrid on the web-apps server, the path is http://web-apps/services.asmx/getGrid.  Adjust the path as needed to your .asmx file.
  3. HTTP Authentication for XML file:  This screen deals with security.  I typically work inside a corporate firewall without security, so I leave these fields blank.  If necessary, fill in the User Id and Password.
  4. Schema file type and location:  I put my schema files on the server,  but usually test with a local XSD file.  Choose HTTP and the path, if the file is on your server.  Otherwise, if the file is local, choose Use Local Schema and point the path to the local schema.
  5. HTTP Parameters:  Click the Add Property … button to add your parameters.  The Value can be left blank, but the Property must be filled in with the parameter names.  Service parameters are case sensitive, so make sure that the case matches.
  6. Clicking Finish will take you back to the data screen.  You will be given an options for the XPaths to the data in your source.  If successful, you will then have data from a web service in your report.


* Tested on CR XI R2/CR 2008