Finding Related Categories
Note: The Microsoft UDDI SDK is not supported by or included in Microsoft Windows versions after Microsoft Windows Server 7. The Microsoft UDDI V3 SDK is included with Microsoft BizTalk Server. For more information about the Microsoft UDDI V3 SDK, see Microsoft BizTalk Server documentation
This topic describes how to get the child categories that are related to a specified category that is available on a UDDI server.
Purpose
This topic shows how to find categories that are related to a specified category on a UDDI server. Specifically, this example shows how to get the child categories of a given category. With minor code modifications, you can also retrieve parent categories.
Prerequisites and Requirements
To find the related categories of a specified category, you need to know the categorization scheme and the category name. The example gets the child categories of the root categories. For more information about getting the root categories of a categorization scheme, see Finding Root Categories.
This example requires the following components:
.NET Framework 2.0.
Visual Studio .NET 2003 or later.
A reference to the Microsoft.Uddi Assembly assembly
The following namespaces:
Example Code
This example is a recursive method that shows the child categories of only the first category in each category collection. If you would like to see the child categories of all categories in the categorization scheme, follow the instructions that are in the comments of the example code. The example also has a routine that indents the category name to make the results easier to read.
The following example shows how to use the Visual C# programming language to find the child categories that are related to a specified category.
static void GetChildCategoriesExample(UddiConnection validConnection,
TModelInfo catScheme,
CategoryValue rootValue,
StringBuilder displayText,
int indent)
{
CategoryList childCategoryList = null;
Category parentCategory = new Category( catScheme.TModelKey,
rootValue.KeyValue );
parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child);
GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory );
try
{
childCategoryList = relatedCategories.Send( validConnection );
}
catch( InvalidKeyPassedException invalidKeyPassed )
{
// Insert error-handling code for this exception.
displayText.Append( "Invalid Key Passed." );
}
catch( InvalidUrlPassedException badURL )
{
// Insert error-handling code for this exception.
displayText.Append( "Bad URL" );
}
catch(UddiException genericUDDIException)
{
// Insert error-handling code for this exception.
displayText.Append( genericUDDIException.Message );
}
catch( Exception otherException)
{
// Insert error-handling code for this exception.
displayText.Append( otherException.Message );
displayText.Append( otherException.GetType().ToString() );
}
CategoryValueCollection childCategories = null;
childCategories = childCategoryList.CategoryInfos[0].Children;
foreach(CategoryValue childCategory in childCategories)
{
displayText.Append( "\r\n" );
// This routine indents each line a specified number of spaces
// to make the child categories easier to read.
for( int counter = 1; counter < indent; ++counter )
{
displayText.Append(" ");
}
// End indent routine.
displayText.Append( childCategory.KeyName );
// Display the children of the first category in the collection.
// To display the child categories of all the categories,
// remove the conditional statements.
if(0 == childCategories.IndexOf( childCategory) )
{
GetChildCategoriesExample( validConnection,
catScheme,
childCategory,
displayText,
++indent );
}
}
}
The following example shows how to use the Visual Basic .NET programming language to find the child categories that are related to a specified category.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _
ByVal catScheme As TModelInfo, _
ByVal rootValue As CategoryValue, _
ByVal displayText As StringBuilder, _
ByVal indent As Integer)
Dim childCategoryList As CategoryList
Dim parentCategory As New Category(catScheme.TModelKey, _
rootValue.KeyValue)
parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child)
Dim relatedCategories As New GetRelatedCategories(parentCategory)
Try
childCategoryList = relatedCategories.Send(validConnection)
Catch invalidKeyPassed As InvalidKeyPassedException
' Insert error-handling code for this exception.
displayText.Append("Invalid Key Passed")
Return
Catch badURL As InvalidUrlPassedException
' Insert error-handling code for this exception.
displayText.Append("Bad URL")
Return
Catch genericUDDIException As UddiException
' Insert error-handling code for this exception.
displayText.Append(genericUDDIException.Message)
Return
Catch otherException As Exception
' Insert error-handling code for this exception.
displayText.Append(otherException.Message)
displayText.Append(otherException.GetType.ToString)
Return
End Try
Dim childCategories As CategoryValueCollection
childCategories = childCategoryList.CategoryInfos(0).Children
Dim childCategory As CategoryValue
For Each childCategory In childCategories
displayText.Append(vbCrLf)
' This optional routine indents each line a specified number of spaces
' to make the child categories easier to read.
Dim counter As Integer
For counter = 1 To indent
displayText.Append(" ")
Next
' End routine.
displayText.Append(childCategory.KeyName)
' Display the children of the first category in the collection.
' To display the child categories of all the categories,
' add comment marks to the If and End If lines.
If childCategories.IndexOf(childCategory) = 0 Then
GetChildCategoriesExample(validConnection, _
catScheme, _
childCategory, _
displayText, _
indent + 1)
End If
Next
End Sub
Example Result
When you run the example code, the StringBuilder object produces results that are similar to the following list. This is a list generated using the TModelKey property of the ntis-gov:naics:2002 categorization scheme and the KeyValue property of the root category Agriculture, Forestry, Fishing and Hunting:
Agriculture, Forestry, Fishing and Hunting
Crop Production
Oilseed and Grain Farming
Soybean Farming
Soybean Farming-This category does not have any child categories.
Oilseed (except Soybean) Farming
Dry Pea and Bean Farming
Wheat Farming
Corn Farming
Rice Farming
Other Grain Farming
Vegetable and Melon Farming
Fruit and Tree Nut Farming
Greenhouse, Nursery, and Floriculture Production
Other Crop Farming
Animal Production
Forestry and Logging
Fishing, Hunting and Trapping
Support Activities for Agriculture and Forestry
Implementation Steps
The following sections show how to implement the example:
Implementation Steps in C#
Create a method that accepts the following parameters:
A valid UddiConnection object.
A TModelInfo object. This object contains the categorization scheme that contains the specified category with the child categories that you want to find.
A CategoryValue object. This object represents the specified category with the child categories that you want to find.
A StringBuilder object. This object is used to contain the information about the child categories.
An integer variable that is used to indent category names.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { }
Create a CategoryList variable and initialize it to null. This variable will contain the results of the message from the UDDI server.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; }
Create an instance of the Category class using the Category constructor method with the TModelKey and the KeyValue passed to the method. This object will be used to create the message that is sent to the UDDI server to get the related categories.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); }
Using the Add method, set the RelationshipQualifiers property of the Category object to the child member of the RelationshipQualifier enumeration.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); }
Create an instance of the GetRelatedCategories class using the GetRelatedCategories constructor method with the Category object that was created in the previous step. This object is the message that will be sent to the UDDI server.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); }
Transmit the request to the UDDI server by using the Send method with the UddiConnection object passed into the method. The CategoryList variable receives the results of the request.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); childCategoryList = relatedCategories.Send( validConnection ); }
Handle any exceptions that might occur by using a try-catch statement. Some possible exceptions are shown in the example code. Wrap the request in the try statement and handle any exceptions in the catch statement.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); try { childCategoryList = relatedCategories.Send( validConnection ); } catch( InvalidKeyPassedException invalidKeyPassed ) { // Insert error-handling code for this exception. displayText.Append( "Invalid Key Passed." ); } catch( InvalidUrlPassedException badURL ) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); } catch(UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); } }
Create a CategoryValueCollection variable and initialize it to null. This variable will contain the related categories collection from the CategoryList variable.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); try { childCategoryList = relatedCategories.Send( validConnection ); } catch( InvalidKeyPassedException invalidKeyPassed ) { // Insert error-handling code for this exception. displayText.Append( "Invalid Key Passed." ); } catch( InvalidUrlPassedException badURL ) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); } catch(UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); } CategoryValueCollection childCategories = null; }
Set the CategoryValueCollection variable to the CategoryInfos property of the CategoryList object. The CategoryInfos property is a property of the Children property.
Note
The CategoryList variable contains only one collection of related categories because the example finds the related categories of single category. If you were to specify multiple categories to search, the CategoryInfos property would contain a collection array of related categories for each specified category. You would then iterate the collection array to find each collection for each specified category.
To find related categories of multiple categories, add each category to a CategoryCollection object and then use the GetRelatedCategories constructor method with the CategoryCollection object to create an instance of the GetRelatedCategories class. For more information, see GetRelatedCategories.static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); try { childCategoryList = relatedCategories.Send( validConnection ); } catch( InvalidKeyPassedException invalidKeyPassed ) { // Insert error-handling code for this exception. displayText.Append( "Invalid Key Passed." ); } catch( InvalidUrlPassedException badURL ) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); } catch(UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); } CategoryValueCollection childCategories = null; childCategories = childCategoryList.CategoryInfos[0].Children; }
Iterate through the CategoryValueCollection object to get information about the related categories. In this example, the name of each related category is added to the StringBuilder object that will be used to display information about the related categories.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); try { childCategoryList = relatedCategories.Send( validConnection ); } catch( InvalidKeyPassedException invalidKeyPassed ) { // Insert error-handling code for this exception. displayText.Append( "Invalid Key Passed." ); } catch( InvalidUrlPassedException badURL ) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); } catch(UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); } CategoryValueCollection childCategories = null; childCategories = childCategoryList.CategoryInfos[0].Children; foreach(CategoryValue childCategory in childCategories) { displayText.Append( "\r\n" ); displayText.Append( childCategory.KeyName ); } }
Optional. To make the results easier to read when you display the contents of the StringBuilder object, you can indent each category name by using the following routine.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); try { childCategoryList = relatedCategories.Send( validConnection ); } catch( InvalidKeyPassedException invalidKeyPassed ) { // Insert error-handling code for this exception. displayText.Append( "Invalid Key Passed." ); } catch( InvalidUrlPassedException badURL ) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); } catch(UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); } CategoryValueCollection childCategories = null; childCategories = childCategoryList.CategoryInfos[0].Children; foreach(CategoryValue childCategory in childCategories) { displayText.Append( "\r\n" ); // This routine indents each line a specified number of spaces // to make the child categories easier to read. for( int counter = 1; counter < indent; ++counter ) { displayText.Append(" "); } // End indent routine. displayText.Append( childCategory.KeyName ); } }
Optional. To find the child related categories of each category, you can recursively call this method. This example gets only the child categories of the first category in the collection.
static void GetChildCategoriesExample(UddiConnection validConnection, TModelInfo catScheme, CategoryValue rootValue, StringBuilder displayText, int indent) { CategoryList childCategoryList = null; Category parentCategory = new Category( catScheme.TModelKey, rootValue.KeyValue ); parentCategory.RelationshipQualifiers.Add( RelationshipQualifier.child); GetRelatedCategories relatedCategories = new GetRelatedCategories( parentCategory ); try { childCategoryList = relatedCategories.Send( validConnection ); } catch( InvalidKeyPassedException invalidKeyPassed ) { // Insert error-handling code for this exception. displayText.Append( "Invalid Key Passed." ); } catch( InvalidUrlPassedException badURL ) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); } catch(UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); } CategoryValueCollection childCategories = null; childCategories = childCategoryList.CategoryInfos[0].Children; foreach(CategoryValue childCategory in childCategories) { displayText.Append( "\r\n" ); // This routine indents each line a specified number of spaces // to make the child categories easier to read. for( int counter = 1; counter < indent; ++counter ) { displayText.Append(" "); } // End indent routine. displayText.Append( childCategory.KeyName ); // Display the children of the first category in the collection. If you // To display the child categories of all the categories, // remove the conditional statements. if(0 == childCategories.IndexOf( childCategory) ) { GetChildCategoriesExample( validConnection, catScheme, childCategory, displayText, ++indent ); } } }
Implementation Steps In Visual Basic .NET
Create a method that accepts the following parameters:
A valid UddiConnection object.
A TModelInfo object. This object contains the categorization scheme that contains the specified category with the child categories that you want to find.
A CategoryValue object. This object represents the specified category with the child categories that you want to find.
A StringBuilder object. This object is used to contain the information about the child categories.
An integer variable that is used to indent category names.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) End Sub
Create a CategoryList variable that will be used to contain the results of the message from the UDDI server.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList End Sub
Create an instance of the Category class using the Category constructor method with the TModelKey and the KeyValue passed to the method. This object will be used to create the message sent to the UDDI server to get the related categories.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) End Sub
Using the Add method, set the RelationshipQualifiers property of the Category object to the child member of the RelationshipQualifier enumeration.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) End Sub
Create an instance of the GetRelatedCategories class using the GetRelatedCategories constructor method with the Category object created in the previous step. This object is the message that will be sent to the UDDI server.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) End Sub
Transmit the request to the UDDI server by using the Send method with the UddiConnection object passed into the method. The CategoryList variable receives the results of the request.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) childCategoryList = relatedCategories.Send(validConnection) End Sub
Handle any exceptions that may occur by using a Try...Catch statement. Some possible exceptions are shown in the example code. Wrap the request in the Try statement and handle any exceptions in the Catch statement.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) Try childCategoryList = relatedCategories.Send(validConnection) Catch invalidKeyPassed As InvalidKeyPassedException ' Insert error-handling code for this exception. displayText.Append("Invalid Key Passed") Return Catch badURL As InvalidUrlPassedException ' Insert error-handling code for this exception. displayText.Append("Bad URL") Return Catch genericUDDIException As UddiException ' Insert error-handling code for this exception. displayText.Append(genericUDDIException.Message) Return Catch otherException As Exception ' Insert error-handling code for this exception. displayText.Append(otherException.Message) displayText.Append(otherException.GetType.ToString) Return End Try End Sub
Create a CategoryValueCollection variable that contains the related categories collection from the CategoryList variable.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) Try childCategoryList = relatedCategories.Send(validConnection) Catch invalidKeyPassed As InvalidKeyPassedException ' Insert error-handling code for this exception. displayText.Append("Invalid Key Passed") Return Catch badURL As InvalidUrlPassedException ' Insert error-handling code for this exception. displayText.Append("Bad URL") Return Catch genericUDDIException As UddiException ' Insert error-handling code for this exception. displayText.Append(genericUDDIException.Message) Return Catch otherException As Exception ' Insert error-handling code for this exception. displayText.Append(otherException.Message) displayText.Append(otherException.GetType.ToString) Return End Try Dim childCategories As CategoryValueCollection End Sub
Set the CategoryValueCollection variable to the CategoryInfos property of the CategoryList object. The CategoryInfos property is a property of the Children property.
Note
The CategoryList variable contains only one collection of related categories because the example finds the related categories of single category. If you were to specify multiple categories to search, the CategoryInfos property would contain a collection array of related categories for each specified category. You would then iterate the collection array to find each collection for each specified category. To find related categories of multiple categories, add each category to a CategoryCollection object and then use the GetRelatedCategories constructor method with the CategoryCollection object to create an instance of the GetRelatedCategories class. For more information, see GetRelatedCategories.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) Try childCategoryList = relatedCategories.Send(validConnection) Catch invalidKeyPassed As InvalidKeyPassedException ' Insert error-handling code for this exception. displayText.Append("Invalid Key Passed") Return Catch badURL As InvalidUrlPassedException ' Insert error-handling code for this exception. displayText.Append("Bad URL") Return Catch genericUDDIException As UddiException ' Insert error-handling code for this exception. displayText.Append(genericUDDIException.Message) Return Catch otherException As Exception ' Insert error-handling code for this exception. displayText.Append(otherException.Message) displayText.Append(otherException.GetType.ToString) Return End Try Dim childCategories As CategoryValueCollection. childCategories = childCategoryList.CategoryInfos(0).Children End Sub
Iterate through the CategoryValueCollection object to get information about the related categories. In this example, each the name of each related category is added to the StringBuilder object that will be used to display this information.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) Try childCategoryList = relatedCategories.Send(validConnection) Catch invalidKeyPassed As InvalidKeyPassedException ' Insert error-handling code for this exception. displayText.Append("Invalid Key Passed") Return Catch badURL As InvalidUrlPassedException ' Insert error-handling code for this exception. displayText.Append("Bad URL") Return Catch genericUDDIException As UddiException ' Insert error-handling code for this exception. displayText.Append(genericUDDIException.Message) Return Catch otherException As Exception ' Insert error-handling code for this exception. displayText.Append(otherException.Message) displayText.Append(otherException.GetType.ToString) Return End Try Dim childCategories As CategoryValueCollection childCategories = childCategoryList.CategoryInfos(0).Children Dim childCategory As CategoryValue For Each childCategory In childCategories displayText.Append(vbCrLf) displayText.Append(childCategory.KeyName) Next End Sub
Optional. To make the results easier to read when you display the contents of the StringBuilder object, you can indent each category name by using the following routine.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) Try childCategoryList = relatedCategories.Send(validConnection) Catch invalidKeyPassed As InvalidKeyPassedException ' Insert error-handling code for this exception. displayText.Append("Invalid Key Passed") Return Catch badURL As InvalidUrlPassedException ' Insert error-handling code for this exception. displayText.Append("Bad URL") Return Catch genericUDDIException As UddiException ' Insert error-handling code for this exception. displayText.Append(genericUDDIException.Message) Return Catch otherException As Exception ' Insert error-handling code for this exception. displayText.Append(otherException.Message) displayText.Append(otherException.GetType.ToString) Return End Try Dim childCategories As CategoryValueCollection childCategories = childCategoryList.CategoryInfos(0).Children Dim childCategory As CategoryValue For Each childCategory In childCategories displayText.Append(vbCrLf) ' This optional routine indents each line a specified number of spaces ' to make the child categories easier to read. Dim counter As Integer For counter = 1 To indent displayText.Append(" ") Next ' End routine displayText.Append(childCategory.KeyName) Next End Sub
Optional. To find the child categories of each category, you can recursively call this method. This example gets only the child categories of the first category in the collection.
Sub GetChildCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catScheme As TModelInfo, _ ByVal rootValue As CategoryValue, _ ByVal displayText As StringBuilder, _ ByVal indent As Integer) Dim childCategoryList As CategoryList Dim parentCategory As New Category(catScheme.TModelKey, _ rootValue.KeyValue) parentCategory.RelationshipQualifiers.Add(RelationshipQualifier.child) Dim relatedCategories As New GetRelatedCategories(parentCategory) Try childCategoryList = relatedCategories.Send(validConnection) Catch invalidKeyPassed As InvalidKeyPassedException ' Insert error-handling code for this exception. displayText.Append("Invalid Key Passed") Return Catch badURL As InvalidUrlPassedException ' Insert error-handling code for this exception. displayText.Append("Bad URL") Return Catch genericUDDIException As UddiException ' Insert error-handling code for this exception. displayText.Append(genericUDDIException.Message) Return Catch otherException As Exception ' Insert error-handling code for this exception. displayText.Append(otherException.Message) displayText.Append(otherException.GetType.ToString) Return End Try Dim childCategories As CategoryValueCollection childCategories = childCategoryList.CategoryInfos(0).Children Dim childCategory As CategoryValue For Each childCategory In childCategories displayText.Append(vbCrLf) ' This optional routine indents each line a specified number of spaces ' to make the child categories easier to read. Dim counter As Integer For counter = 1 To indent displayText.Append(" ") Next ' End routine displayText.Append(childCategory.KeyName) ' Display the children of the first category in the collection. ' To display the child categories of all the categories, ' add comment marks to the If and End If lines. If childCategories.IndexOf(childCategory) = 0 Then GetChildCategoriesExample(validConnection, _ catScheme, _ childCategory, _ displayText, _ indent + 1) End If Next End Sub
See Also
Reference
Category
Category
CategoryList
CategoryValueCollection
Children
CategoryInfos
KeyValue
GetRelatedCategories
GetRelatedCategories
Send
TModelKey
UddiConnection
InquireUrl
ExtensionsUrl
Concepts
Microsoft.Uddi Assembly
Finding Root Categories
Finding Categorization Schemes
Specifying Access Points