Showing posts with label web services. Show all posts
Showing posts with label web services. Show all posts

27 August 2010

Solving the ASP.Net Double Hop problem

This article is in debt to Andrew Hay's excellent writeup on how he solved his double-hop problem.

The double-hop problem occurs when a central application calls a web-service on a second server, but the credentials are not passed to the second server, causing the web-service call to fail.  This is because IIS does not pass on the credentials to the second machine.

When this happens you will see the error:

System.Net.WebException: The request failed with HTTP status 401: Unauthorized at...

The worst part of this error is that the web service will work from your machine, but not when you move it to the server for testing.

The double-hop will most likely happen if you use the CredentialCache.DefaultNetworkCredentials or CredentialCache.DefaultCredentials to authenticate the service call.


Problem Solved: System.Net.NetworkCredential

The fix is relatively simple:

  • Create a new System.Net.NetworkCredential that uses a service account.  Use this to authenticate the service call.
  • Add the service account to the users group on the target server where the web service is located.

The pseudo code looks like this:

Dataset ds = new DataSet("Grid"); 
using(MyService ws = new MyService) {
     char[] delim = ";".ToCharArray(); 
     string[] creds = ConfiigurationManager.AppSettings["ServiceAcct"].Split(delim);
     ws.Credentials = new System.Net.NetworkCredential(creds[0], creds[1], creds[2]); 
     ds = ws.getDataSet(arg1, arg2);
return ds; 


The Web.Config would have an application setting of "ServiceAccount" with the value "User;Password;Domain".

Follow up with adding the service account to the Users Group on the machine that hosts the web service.  This should solve the

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

19 August 2008

Installing Business Objects Web Services

We recently installed the Business Objects Enterprise at this client to get web access to crystal reports.  One of the excellent features (of many) of this software is the ability to incorporate the web application into other applications. 

Reports are exposed in two ways:

  • The Enterprise Server can launch reports via URL, which is an easy way to launch reports directly from inside any application.  The disadvantage is that the URLs are static and have to be coded every time the BOE repository is updated.  For example, if a new report is added for an application, the new URL has to be added to the list and possibly coded back into the application.  The advantage to URL access is that it's simple to implement and works with no further server modification.
  • Business Objects publish an extensive web services API.  However, the instructions for installation that ship with BOE can be pretty confusing and daunting.  In the end, I found the instructions incomplete and difficult to follow.  I think installation complexity is the biggest implementation impediment.  However, if one can get through the installation, the improved functionality is well worth the pain.

The installation steps I followed can be found by clicking here.  (The directions here are for XI R2/Windows Server 2003.)

Start by installing Business Objects and making sure Tomcat is installed.  In our case, Tomcat was installed by default.

The BOE web services installation instructions are found by opening the Dev Library and navigating to Web Services SDK > Web Services Server Components > Administrator Guide > Installing Business Objects web services.  There are several steps worth reviewing in this document, but I have found a simpler way as follows.

Then do the following: 

  1. Ensure that the Java SDK is installed.  On the server, open the command prompt and type java -fullversion.  If Java is installed, the version is returned.  If not, follow the instructions for downloading the Java SDK.
  2. Locate the dswsbobje.war file.  This is the file that creates the web services.  The file automatically installed in following directory on Windows servers:   [install_dir]\BusinessObjects Enterprise 11.5\Web Services\en\
  3. Deploy the .war file.  Copy the .war file into the [install]\Tomcat\webapps directory.  If a directory with the same name of the .war file already exists (in this case dswsbobje), rename it to 'zdswsbobje' as the installation will not overwrite the existing files.  Restart the Tomcat service, either through the Tomcat management console or the Business Objects Central Configuration Manager (CMC).  Tomcat will create a directory in the webapps folder with the same name as the .war file.
  4. Confirm the installation.  Before testing the service, run access the happydsws.jsp page to make sure all the services installed correctly.   The page will display a list of found components and any missing components.  The page can be found at http://[server name]:[port]/dswsbobje/happydsws.jsp.
  5. Access the services.  If the services are working properly, they can be accessed at http://[server name]:[port]/services.