Accessing the UDDI Programmatically


If you are accessing the UDDI from another system, or you would like to access it as a user would access it, you need to use the URL http://[machine name]/uddipublic. This is the public URL that people coming into your UDDI will use to determine information about the available services. In this section you will put together a small application to read the information about Web services programmatically. There can be many reasons why you might want to do this. These reasons include being able to check new additions and changes to UDDI services, and to incorporate Web services programmatically. There will undoubtedly be many other reasons to do so as Web services expand and are used by more enterprises.

start sidebar
Web Services in the Enterprise

There has been a lot of talk lately about Web services and their possibilities, but at the time of this writing there are few companies putting Web services to use in a public (external of the enterprise) manner. As I write this chapter, the two major players are Microsoft (with its MapPoint Web service and the new .NET Alerts Web service) and Amazon.com. I suspect that the majority of enterprises will hold off on implementing any type of public Web service for at least the next six months until enterprises can get a good grasp of what a Web service is and how to use it.

Currently enterprises should be putting together a list of standards for use within the organization for creating and organizing the services that they have available. At the beginning these will probably be simple internal Web services for things such as a customer database or an employee database—information that is typically spread out or duplicated all over an enterprise. By coming up with uniform standards, the task of searching for Web services becomes much easier. But beware—all UDDIs are not created equal. Even though there is a UDDI standard/specification, each UDDI works a little differently unfortunately. Much of what you can do as developers will fail if the major players cannot agree to a true common standard; and in the long run, the businesses that want to use UDDI will be the ones that suffer.

end sidebar

To be able to access the UDDI programmatically, you need to download and install the UDDI Software Development Kit (SDK) version 2.0 from http://www.microsoft.com/downloads/release.asp?releaseid=35940.

Note

At the time this writing, only the UDDI SDK version 2.0 Beta is available. It is not backward compatible with the UDDI 1.0 specification. This URL may become out-of-date, in which case you can check http://msdn.microsoft.com/uddi.

Note

As of this writing, the UDDI version 3.0 specification is current. There is no SDK for this at this time.

Introducing the UDDI Object Model

You will build a small application that will programmatically retrieve entries from the UDDI. Regardless of how many providers or services there are, the code to retrieve that information remains the same. To that end, this application will give you a good start toward building a full-fledged system to handle UDDI tasks through code.

Although the code to get the data can be fairly long winded, it is pretty straightforward once you understand the basic structure of the UDDI objects; see the UDDI object maps shown on the inside front and back covers of this book. The current documentation is pretty scant as of this writing because this is only a beta SDK. Many of the namespaces and objects will look familiar to you if you spend some time looking at a UDDI directory. The Uddi namespace contains the bulk of the objects that you will be working with, and it provides an entry to most of the other objects available to you in the other namespaces. For example, under the Business namespace you will see the BusinessEntity object, and under the Uddi namespace you will see a method called GetBusinessDetail that returns the BusinessEntityCollection. This illustrates how you can drill down into the UDDI starting at the top, which is what you will do in your little application.

Building the UDDI Explorer

Start by creating a new Windows project called UddiExplorer, and then add a reference to the Microsoft.Uddi.Sdk assembly—this will be in the list of .NET Framework components because it is installed in the Global Access Cache (GAC). When you are done building the form, it will look like the form shown in Figure 11-23.

click to expand
Figure 11-23: The UDDI Explorer interface

Add the controls to the form and name them according to Table 11-3.

Table 11-3: The UDDI Explorer Controls

Control

Name

Text

Label

Business

Textbox

txtBusiness

Label

Services

Treeview

tvwServices

Label

Service Description

Textbox

txtServiceDescription

Button

btnSearch

&Search

Button

btnDetails

&Details

Button

btnClose

&Close

The only property you need to alter is the Multiline property of the txtDetails textbox; set it to true. Now that you have your form, switch over to the code view and add the following header information:

 Option Explicit On Option Strict On Imports Microsoft Imports Microsoft.Uddi Imports Microsoft.Uddi.Api 

Next, add the code for the btnSearch_Click method to the form as shown in Listing 11-14.

Listing 11-14: The btnSearch_Click Method

start example
 Private Sub btnSearch_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnSearch.Click      Try           Cursor = Cursors.WaitCursor           Inquire.Url = "http://localhost/uddipublic/inquire.asmx"           Dim fb As New FindBusiness           Dim bList As BusinessList           Dim bus As Business.BusinessInfo           fb.Names.Add(Me.txtBusiness.Text)           bList = fb.Send           For Each bus In bList.BusinessInfos                Dim ndeBus As New TreeNode(bus.Name)                ndeBus.Tag = bus.BusinessKey                Dim gBusinessDetail As New GetBusinessDetail                Dim bDetail As BusinessDetail                gBusinessDetail.BusinessKeys.Add(bus.BusinessKey)                bDetail = gBusinessDetail.Send                Dim i As Integer                Dim gServices As New GetServiceDetail                Dim bService As ServiceDetail                Dim bEntity As Business.BusinessEntity                For Each bEntity In bDetail.BusinessEntities                     For i = 0 To bEntity.BusinessServices.Count - 1                          Dim nde As New _                          TreeNode(bEntity.BusinessServices(i).Names(0).Text)                          nde.Tag = bEntity.BusinessServices(i).ServiceKey                          ndeBus.Nodes.Add(nde)                     Next                Next                tvwServices.Nodes.Add(ndeBus)           Next      Catch ex As Exception           MessageBox.Show(ex.Message)      Finally           Cursor = Cursors.Default      End Try End Sub 
end example

Let's examine this code in detail so that you can figure out what is happening. To begin with, you need to know where the UDDI is located and where you can inquire about the services it contains. You accomplish this by setting the inquiry URL with the following line:

 Inquire.Url = "http://localhost/uddipublic/inquire.asmx" 

Next you need to find the business for which you are looking. Every item in a UDDI that can be searched has a Find object (FindBusiness, FindService, FindTModel, and so on). In this case you are going to be looking for the business.

Note

In a practical situation, you will probably want to search for a service that falls within a specific category such as Financial, Customer Information, and so on. You are performing your search this way because of the limited amount of information in your UDDI. The process is the same no matter what you are searching for, so extending this application is simple.

The BusinessInfo object enumerates through the collection of businesses that are returned to you. You can search for as many businesses at a time as you want by adding business names to the FindBusiness object. Finally, to actually go find the businesses, you call the Send method of the FindBusiness object. This call to FindBusiness returns a BusinessList object, which contains all of the businesses that matched your search. Each object that can perform a find in the UDDI has a method called Send:

 Dim fb As New FindBusiness Dim bList As BusinessList Dim bus As Business.BusinessInfo fb.Names.Add(Me.txtBusiness.Text) bList = fb.Send 

Next, you loop through the businesses that were returned to you and store the business name in a tree node. You also store the business key in the node in case you want to drill down into the business (covered next):

 For Each bus In bList.BusinessInfos      Dim ndeBus As New TreeNode(bus.Name)      ndeBus.Tag = bus.BusinessKey 

Now you need to get information about your business to figure out what services the business provides. To do this you declare a GetBusinessDetail object, which performs basically the same function as the FindBusiness object—it searches the UDDI for businesses that match a list of BusinessKeys. As with the FindBusiness object, to perform the search, you call the Send method, which returns a collection of business details:

 Dim gBusinessDetail As New GetBusinessDetail Dim bDetail As BusinessDetail gBusinessDetail.BusinessKeys.Add(bus.BusinessKey) bDetail = gBusinessDetail.Send 

Next you have to dive into finding out what services your business provides. The GetServiceDetail and ServiceDetail perform the same functions as the GetBusinessDetail and BusinessDetail previously mentioned, except at the service level:

 Dim i As Integer Dim gServices As New GetServiceDetail Dim bService As ServiceDetail Dim bEntity As Business.BusinessEntity 

You start off by looping through the business entities returned to you by the call to the GetBusinessDetail object. Within each business, you loop through all of the services provided by that business. For each service you create a new node and set the text property equal to the service name. Each service can have multiple names for various reasons (such as for different languages), but you are only going to take the first one because you have given your services only one name each. Then you set the tag property equal to the service key so you can easily get information about this service later. Finally, you add the node to your root node and you add the root node to the treeview:

      For Each bEntity In bDetail.BusinessEntities           For i = 0 To bEntity.BusinessServices.Count - 1                Dim nde As New TreeNode(bEntity.BusinessServices(i).Names(0).Text)                nde.Tag = bEntity.BusinessServices(i).ServiceKey                ndeBus.Nodes.Add(nde)           Next      Next      tvwServices.Nodes.Add(ndeBus) Next 

You now have enough code to run the application, so run that application and enter the name NorthwindTraders in the Business name textbox (or enter only the first part of the name because a partial search is performed). The form should look like Figure 11-24 after you click the Search button.

click to expand
Figure 11-24: The search results in the UDDI Explorer application

Now you will add the ability to get the details of a particular service. Add the code in Listing 11-15 to Form1. This code allows you to retrieve the details for a given service.

Listing 11-15: The btnDetails_Click Method

start example
 Private Sub btnDetails_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDetails.Click      Dim gServiceDetail As New GetServiceDetail      Dim bService As ServiceDetail      Dim i, j As Integer      gServiceDetail.ServiceKeys.Add(tvwServices.SelectedNode.Tag.ToString)      bService = gServiceDetail.Send      txtDetails.Text = ""      For i = 0 To bService.BusinessServices.Count - 1           txtServiceDescription.Text = "Service Name: " & _           bService.BusinessServices(i).Names(0).Text           txtServiceDescription.Text += ControlChars.CrLf           txtServiceDescription.Text += "Descriptions: " & ControlChars.CrLf           For j = 0 To bService.BusinessServices(i).Descriptions.Count - 1                txtServiceDescription.Text += _                bService.BusinessServices(i).Descriptions(j).Text                txtServiceDescription.Text += ControlChars.CrLf           Next           txtServiceDescription.Text += "Category Bag: " & ControlChars.CrLf           For j = 0 To bService.BusinessServices(i).CategoryBag.Count - 1                txtServiceDescription.Text += "Key Name: " & _                bService.BusinessServices(i).CategoryBag(j).KeyName & _                ControlChars.CrLf                txtServiceDescription.Text += "Key Value: " & _                bService.BusinessServices(i).CategoryBag(j).KeyValue & _                ControlChars.CrLf                txtServiceDescription.Text += "tModel Key: " & _                bService.BusinessServices(i).CategoryBag(j).TModelKey & _                ControlChars.CrLf                txtServiceDescription.Text += ControlChars.CrLf           Next           txtServiceDescription.Text += "Business Key: " & _           bService.BusinessServices(i).BusinessKey           txtServiceDescription.Text += ControlChars.CrLf           txtServiceDescription.Text += "Service Key: " & _           bService.BusinessServices(i).ServiceKey           txtServiceDescription.Text += "Access Point: " & _           bService.BusinessServices(i).BindingTemplates(0).AccessPoint.Text _           & ControlChars.CrLf      Next End Sub 
end example

The code starts out similar to your Search method, except that you are looking to find a service with a key you already know, so you can skip a lot of the extraneous work. Once you get a reference to the service you are looking for, you just pull out all of the information about that service. The most important piece of information is in the last line of this procedure, the BindingTemplate AccessPoint, which provides the URL of the service. By appending ?wsdl to the end of the AccessPoint, you will have the URL needed to use the WSDL utility. When you run the application, click a service node and then click the Details button. The results should look something like Figure 11-25.

click to expand
Figure 11-25: Service details

This small application gives you an overall understanding of the organization of UDDI Server and how to retrieve the information you need, when you need it.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net