Combining Web Services and SQL Server Data Utilizing Business Objects Business View Manager - Part 1
page 4 of 6
by Eric Landes
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 25445/ 76

Creating the Web Service

Now that our database source has a column we can connect, we can create a web service that pulls data from our ERP.  Let me make a side note here.  In many situations like this we may not have a proper foreign key to connect our ERP data to.  Sometimes we might need to join the different data sources on a less than ideal key like a location name instead of an ID.  To keep that to a minimum, try to add the unique ID during design, if possible.

Now let us create the web service.  We are actually going to create the web service using Test Driven Development techniques. 

To start out, we create the interface that both the mock objects and the real methods will utilize.  In this case, I have created a dataset iMfgLocation.xsd that includes a Datatable with the columns that the method will return.  During this article we will be utilizing the mock object class, but will assume that you can create a web service using those same interfaces and returning data in the same way.

For this example we create a class project called ERPReturnCustomers.  The main class for our mock object is called MfgLocationMock.  This object mocks what would be returned by a web service (in this case a datatable).  In other words, it is loading some bogus data, but the data is returned in the same manner real data will be returned.

The sample download included in this article includes the nunit tests used to verify that the mocks work as they should.  Once a web service is implemented, you can then implement another class that returns the real data in the same way. See the code that returns data for the mock object in Listing 2.

Listing 2

public iMfgLocation.MfgLocationDataTable ReturnLocations()
{
  iMfgLocation.MfgLocationDataTable dtNewTable = new
    iMfgLocation.MfgLocationDataTable();
  DataRow drLoad1 = dtNewTable.NewRow();
  drLoad1["ID"= 1;
  drLoad1["LocationName"= "Here";
  drLoad1["PlantManager"= "Larry Bird";
  dtNewTable.Rows.Add(drLoad1);
 
  DataRow drLoad2 = dtNewTable.NewRow();
  drLoad2["ID"= 2;
  drLoad2["LocationName"= "There";
  drLoad2["PlantManager"= "George Bush";
  dtNewTable.Rows.Add(drLoad2);
 
  DataRow drLoad3 = dtNewTable.NewRow();
  drLoad3["ID"= 3;
  drLoad3["LocationName"= "Every where";
  drLoad3["PlantManager"= "George Bush";
  dtNewTable.Rows.Add(drLoad3);
  return dtNewTable;
}

To then set up your web service you would create the class MfgLocation.  In that class, you would have the same method ReturnLocations.  In ReturnLocations the connection to the web service happens.  So the Code may look something like Listing 3.

Listing 3

public iMfgLocation.MfgLocationDataTable ReturnLocations()
{
  iMfgLocation.MfgLocationDataTable dtNewTable = new
    iMfgLocation.MfgLocationDataTable();
  ws_RealWebService wsRealWS = new ws_RealWebService();
  DataSet dsGetData = wsRealWS.ReturnDataMethod();
  // Load Data into dtNewTable
  return dtNewTable;
}

Now that we have created this class, we will later use it to connect to our web service via the ADO.NET data connection in Business Views, which we will cover in part 2 of this article.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-12-07 6:41:51 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search