In working with a large Canadian Law firm this week, I built this lab to help them learn to build Web Services that cater to BDC Web Service Application Definition files. Pretty neat stuff…keep in mind that you have to setup the BDC Editor before performing these steps.
Exercise 1 – Create a BDC App Def File (Web Service)
Purpose:
Create
a BDC Application Definition File with the Microsoft BDC tool. Note that this tool is a basic editor, it
doesn’t implement any advanced functionality.
To do advanced things, you will need to reference the schema file and
build your own xml.
Result: An Application Definition File
Task 1 –Create a Web
Service
- In Visual Studio, create a
new web service project - Click
“File->New->Web Site” - Select “ASP.NET Web
Service” - For location, type
“D:lab workBDCWebService” - Click “Ok”
Task 2 –Create a
return class
- Create a new class to act as
our return type - Right click the
project, select “Add New Item” - Select “Class”
- For name, type
“Product.cs” - Click “Add”
- Click “Yes” to the “App_Code”
directory - Add the following variable to
the class (copy under the “public class Product” line):
|
- Add the following properties
to the class:
|
- Add the following methods to
the class:
|
- Add the following attribute
to the class:
|
- Compile the project, fix any
errors
Task 3 –Implement the
web methods
- Open the Service.cs file
- Add the following using
statements to the file:
|
- Add a property to get a
connection string from the configuration file:
|
- Open the web.config file
- Add the following line to the
<Configuraton><appSettings> element:
|
- Save the file
- Add a method to get a list of
ids:
|
- Add a method to get a single
Product from the database by ProductId:
|
- Add a method to get a single
Product from the database by ProductName:
|
- Add a method to get all the
Products from the database:
|
- Add a helper class called
SqlHelper: - Right click the
project, select “Add New Item” - Select “Class”
- For name, type
“SqlHelper” - Click “Add”
- Paste the code in the 07_Lab07.extra.txt
code snippet file into the file - Compile the project, fix any
errors - Set the web service port to
200 - Click the project in
the solution explorer - In the “Properties”
window, set Dynamic Ports to “false” - Set the Port number to
“2000” - Run the web service, press F5
- Click “Ok” to create the
web.config file - You should see your web
service running on port 2000
Task 4 –Create a BDC
Application Definition file
- Click “Start->All
Programs->Microsoft Business Data Catalog Definition Editor” - The BDC editor will start:
- Click “Add LOB System”
- Click “Connect to Web Service”
- Type the URL of the web
service “http://localhost:2000/BDCWebService/Service.asmx” - Click “Connect”
- Click “Add Web Method” (on
the right side) - Drag all the methods to the design surface (make sure they are all
added to the same Entity)! - GetProductEnumeratorIDs
- GetProduct
- GetProductsByName
- GetProducts
- Click “Ok”
- For the name, type “Products”
- Click “Ok”
- Note how our Instances and
Entities are populated
- Also note how the
Identifiers, Methods and Actions are populated - Right Click on any node,
notice how you get the ability to add a new item that is appropriate for
whatever level you are on in the tree view
- Select the “Enitiy1” node
- In the Property editor,
change the name to “Products”
- Expand the
Products->Methods->GetProductByName->Parameters->Return->Return->Item
nodes
- You will see the properties
of the Product class exposed as fields that will be returned in your BDC
Application! - Right click “Identifier”,
select “Add Identifier” - For Name, type
“ProductId” - For the Type, select
“System.Int32” - Setup an Enumerator method
- Expand GetProductEnumeratorIDs
- Right click
“Instances”, select “Add Method Instance” - Click the “Id
Enumerator” method type - For the name, type
“EnumId” - Click “Ok”
- Setup a SpecificFinder method
- Expand GetProduct
- Right click “Filters”,
select “Add Filter” - For FilterType, select
“Equals” - For Name, type
“ProductId” - Expand
“Parameters->Return->Return” - Select “ProductID”
- Set the Identifier to
“ProductId[Product]” - Right click
“Instances”, select “Add Method Instance” - Click the “SpecificFinder”
method type - For the name, type
“ProductSpecificFinder” - Click “Ok”
- Setup a Finder method
- Expand GetProducts
- Expand
“Parameters->Return->Return->Item” - Select “ProductID”
- Set the Identifier to
“ProductId[Product]” - Right click
“Instances”, select “Add Method Instance” - Click the “Finder”
method type - For the name, type
“ProductFinder” - Click “Ok”
- Right click the “Products”
LobSystem and select “Export”
- Save to your desktop as Lists.xml
- Open the file, review its
contents
Task 5 –Upload your
new BDC Application
- Open the Central
Administration site - Click “SharedServices1”
- Click “Import Application
Definition” - Select your “products.xml”
file - Click “Import”
Task 7 –Create BDC
Web Part
- Open your team site
- Click “Site Actions->Edit
Page” - Select the “Business Data
List” web part - Click “Add”
- Click “Open the tool pane”
link - For Type, click the browse
button - Select the “Products”
business Data Type - Click “Ok”
- Click “Ok”
- You should see a listing of
all the products from the web service!