Finding Root 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 find the root categories of a categorization scheme that is available on a UDDI server.
Purpose
This topic shows how to find the root categories of the specified categorization scheme. After finding the root categories, you can enumerate all of the categories that are related to each root category. For more information, see Finding Related Categories.
Prerequisites and Requirements
To find the root categories used in a categorization scheme, you need a categorization scheme that is used by a UDDI server. For more information, see Finding Categorization Schemes.
This example requires the following components:
.NET Framework 2.0.
Visual Studio .NET 2003 or later.
A valid UddiConnection object with an inquiry URL and an extension URL. For more information, see Initializing a Connection.
A categorization scheme that is available on a UDDI server. For more information, see Finding Categorization Schemes.
The following namespaces:
Example Code
The following Visual C# example shows how to find the root categories of a categorization scheme.
static void GetRootCategoriesExample( UddiConnection validConnection,
TModelInfo catSchemeObject,
StringBuilder displayText )
{
CategoryList rootCategoryList = null;
Category rootCategory = new Category( catSchemeObject.TModelKey );
rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root );
GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory );
try
{
rootCategoryList = rootCategories.Send( validConnection );
}
catch(InvalidKeyPassedException invalidKeyPassed)
{
// Insert error-handling code for this exception.
displayText.Append( "Invalid key passed." );
return;
}
catch(InvalidUrlPassedException badURL)
{
// Insert error-handling code for this exception.
displayText.Append( "Bad URL" );
return;
}
catch( UddiException genericUDDIException)
{
// Insert error-handling code for this exception.
displayText.Append( genericUDDIException.Message );
return;
}
catch( Exception otherException)
{
// Insert error-handling code for this exception.
displayText.Append( otherException.Message );
displayText.Append( otherException.GetType().ToString() );
return;
}
CategoryValueCollection rootValues;
rootValues = rootCategoryList.CategoryInfos[0].Roots;
foreach(CategoryValue rootValue in rootValues)
{
displayText.Append("\r\n " + rootValue.KeyName);
if( rootValues.IndexOf( rootValue ) < 1 )
{
GetChildCategoriesExample( validConnection,
catSchemeObject,
rootValue,
displayText,
3 );
}
}
}
The following Visual Basic .NET example shows how to find the root categories of a categorization scheme.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _
ByVal catSchemeObject As TModelInfo, _
ByVal displayText As StringBuilder)
Dim rootCategoryList As CategoryList
Dim rootCategory As New Category(catSchemeObject.TModelKey)
rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root)
Dim relatedCategories As New GetRelatedCategories(rootCategory)
Try
rootCategoryList = 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 rootCategories As CategoryValueCollection
rootCategories = rootCategoryList.CategoryInfos(0).Roots
Dim rootValue As CategoryValue
For Each rootValue In rootCategories
displayText.Append(vbCrLf + " " + rootValue.KeyName)
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 of root categories from the ntis-gov:naics:1997 categorization scheme:
ntis-gov:naics:1997
Agriculture, Forestry, Fishing and Hunting
Mining
Utilities
Construction
Manufacturing
Manufacturing
Manufacturing
Wholesale Trade
Retail Trade
Retail Trade
Transportation and Warehousing
Transportation and Warehousing
Information
Finance and Insurance
Real Estate and Rental and Leasing
Professional, Scientific, and Technical Services
Management of Companies and Enterprises
Administrative and Support and Waste Management and Remediation Services
Educational Services
Health Care and Social Assistance
Arts, Entertainment, and Recreation
Accommodation and Food Services
Other Services (except Public Administration)
Public Administration
Implementation Steps
The following sections show how to implement the example code:
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 with the related child categories.
A StringBuilder object. This object contains the information about the related child categories.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { }
Create a CategoryList variable and initialize it to null. This variable will contain the results of the message from the UDDI server.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; }
Create an instance of the Category class using the Category constructor method with the TModelKey passed to the method. This object will be used to create the message that is sent to the UDDI server to find the root categories.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); }
Using the Add method, set the RelationshipQualifiers property of the Category object to the root member of the RelationshipQualifier enumeration.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); }
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 GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory ); }
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 GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory ); rootCategoryList = rootCategories.Send( validConnection ); }
Handle any exceptions that may occur by using a try-catch statement. The example code shows some exceptions that you might want to handle. Wrap the request in the try statement and handle any exceptions in the catch statement.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory ); try { rootCategoryList = rootCategories.Send( validConnection ); } catch(InvalidKeyPassedException invalidKeyPassed) { // Insert error-handling code for this exception. displayText.Append( "Invalid key passed." ); return; } catch(InvalidUrlPassedException badURL) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); return; } catch( UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); return; } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); return; } }
Create a CategoryValueCollection variable and initialize it to null. This variable will contain the root category collection from the CategoryList variable.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory ); try { rootCategoryList = rootCategories.Send( validConnection ); } catch(InvalidKeyPassedException invalidKeyPassed) { // Insert error-handling code for this exception. displayText.Append( "Invalid key passed." ); return; } catch(InvalidUrlPassedException badURL) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); return; } catch( UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); return; } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); return; } CategoryValueCollection rootValues; }
Set the CategoryValueCollection variable to the CategoryInfos property of the CategoryList object. The CategoryInfos property is a property of the Roots property.
Note
The CategoryList variable contains only one collection of root categories because the example finds the root categories of a single categorization scheme. If you were to specify multiple categorization schemes to search, the CategoryInfos property would contain a collection array of root categories for each specified categorization scheme. You would then iterate the collection array to find each collection for each specified category.
To find root categories of multiple categorization schemes, create an instance of the Category class using the Category constructor method with the TModelKey of each categorization scheme. 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 GetRootCategoriesExample( UddiConnection validConnection,
TModelInfo catSchemeObject,
StringBuilder displayText )
{
CategoryList rootCategoryList = null;
Category rootCategory = new Category( catSchemeObject.TModelKey );
rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root );
GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory );
try
{
rootCategoryList = rootCategories.Send( validConnection );
}
catch(InvalidKeyPassedException invalidKeyPassed)
{
// Insert error-handling code for this exception.
displayText.Append( "Invalid key passed." );
return;
}
catch(InvalidUrlPassedException badURL)
{
// Insert error-handling code for this exception.
displayText.Append( "Bad URL" );
return;
}
catch( UddiException genericUDDIException)
{
// Insert error-handling code for this exception.
displayText.Append( genericUDDIException.Message );
return;
}
catch( Exception otherException)
{
// Insert error-handling code for this exception.
displayText.Append( otherException.Message );
displayText.Append( otherException.GetType().ToString() );
return;
}
CategoryValueCollection rootValues;
rootValues = rootCategoryList.CategoryInfos[0].Roots;
}
Iterate through the CategoryValueCollection object to get information about the root categories. In this example, the name of each root category is added to the StringBuilder object that displays information about root categories.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory ); try { rootCategoryList = rootCategories.Send( validConnection ); } catch(InvalidKeyPassedException invalidKeyPassed) { // Insert error-handling code for this exception. displayText.Append( "Invalid key passed." ); return; } catch(InvalidUrlPassedException badURL) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); return; } catch( UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); return; } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); return; } CategoryValueCollection rootValues; rootValues = rootCategoryList.CategoryInfos[0].Roots; foreach(CategoryValue rootValue in rootValues) { displayText.Append("\r\n " + rootValue.KeyName); } }
Optional. To find the related categories of each root category, you can create an optional method that finds the related categories and then recursively call this optional method. For more information about creating a method that finds root categories, see, Finding Related Categories. This example calls the optional method for the first root category in the collection.
static void GetRootCategoriesExample( UddiConnection validConnection, TModelInfo catSchemeObject, StringBuilder displayText ) { CategoryList rootCategoryList = null; Category rootCategory = new Category( catSchemeObject.TModelKey ); rootCategory.RelationshipQualifiers.Add( RelationshipQualifier.root ); GetRelatedCategories rootCategories = new GetRelatedCategories( rootCategory ); try { rootCategoryList = rootCategories.Send( validConnection ); } catch(InvalidKeyPassedException invalidKeyPassed) { // Insert error-handling code for this exception. displayText.Append( "Invalid key passed." ); return; } catch(InvalidUrlPassedException badURL) { // Insert error-handling code for this exception. displayText.Append( "Bad URL" ); return; } catch( UddiException genericUDDIException) { // Insert error-handling code for this exception. displayText.Append( genericUDDIException.Message ); return; } catch( Exception otherException) { // Insert error-handling code for this exception. displayText.Append( otherException.Message ); displayText.Append( otherException.GetType().ToString() ); return; } CategoryValueCollection rootValues; rootValues = rootCategoryList.CategoryInfos[0].Roots; foreach(CategoryValue rootValue in rootValues) { displayText.Append("\r\n " + rootValue.KeyName); if( rootValues.IndexOf( rootValue ) < 1 ) { GetChildCategoriesExample( validConnection, catSchemeObject, rootValue, displayText, 3 ); } } }
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 StringBuilder object. This object contains the information about the child categories.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) End Sub
Create a CategoryList variable that will contain the results of the message from the UDDI server.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList End Sub
Create an instance of the Category class using the Category constructor method with the TModelKey passed to the method. This object will be used to create the message that is sent to the UDDI server to find the root categories.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) End Sub
Using the Add method, set the RelationshipQualifiers property of the Category object to the root member of the RelationshipQualifier enumeration.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) End Sub
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.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) Dim relatedCategories As New GetRelatedCategories(rootCategory) 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 GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) Dim relatedCategories As New GetRelatedCategories(rootCategory) rootCategoryList = relatedCategories.Send(validConnection) End Sub
Handle any exceptions that may occur by using a try-catch statement. The example code shows some exceptions that you might want to handle. Wrap the request in the try statement and handle any exceptions in the catch statement.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) Dim relatedCategories As New GetRelatedCategories(rootCategory) Try rootCategoryList = 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 and initialize it to null. This variable will contain the root category collection from the CategoryList variable.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) Dim relatedCategories As New GetRelatedCategories(rootCategory) Try rootCategoryList = 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 rootCategories As CategoryValueCollection End Sub
Set the CategoryValueCollection variable to the Roots property of the CategoryInfos property of the CategoryList object.
Note
The CategoryList variable contains only one collection of root categories because the example finds the root categories of single categorization scheme. If you specify multiple categorization schemes to search, the CategoryInfos property would contain a collection array of root categories for each specified categorization scheme. You would then iterate the collection array to find each collection for each specified category.
To find root categories of multiple categorization schemes, create an instance of the Category class using the Category constructor method with the TModelKey of each categorization scheme. 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 GetRootCategoriesExample(ByVal validConnection As UddiConnection, _
ByVal catSchemeObject As TModelInfo, _
ByVal displayText As StringBuilder)
Dim rootCategoryList As CategoryList
Dim rootCategory As New Category(catSchemeObject.TModelKey)
rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root)
Dim relatedCategories As New GetRelatedCategories(rootCategory)
Try
rootCategoryList = 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 rootCategories As CategoryValueCollection
rootCategories = rootCategoryList.CategoryInfos(0).Roots
End Sub
Iterate through the CategoryValueCollection object to get information about the root categories. In this example, the name of each root category is added to the StringBuilder object that displays information about root categories.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) Dim relatedCategories As New GetRelatedCategories(rootCategory) Try rootCategoryList = 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 rootCategories As CategoryValueCollection rootCategories = rootCategoryList.CategoryInfos(0).Roots Dim rootValue As CategoryValue For Each rootValue In rootCategories displayText.Append(vbCrLf + " " + rootValue.KeyName) Next End Sub
Optional. To find the related categories of each root category, you can create an optional method that finds the related categories and then recursively call this new method. For more information about creating a method that finds root categories, Finding Related Categories. This example calls the optional method for the first root category in the collection.
Sub GetRootCategoriesExample(ByVal validConnection As UddiConnection, _ ByVal catSchemeObject As TModelInfo, _ ByVal displayText As StringBuilder) Dim rootCategoryList As CategoryList Dim rootCategory As New Category(catSchemeObject.TModelKey) rootCategory.RelationshipQualifiers.Add(RelationshipQualifier.root) Dim relatedCategories As New GetRelatedCategories(rootCategory) Try rootCategoryList = 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 rootCategories As CategoryValueCollection rootCategories = rootCategoryList.CategoryInfos(0).Roots Dim rootValue As CategoryValue For Each rootValue In rootCategories displayText.Append(vbCrLf + " " + rootValue.KeyName) If rootCategories.IndexOf(rootValue) < 1 Then GetChildCategoriesExample(validConnection, _ catSchemeObject, _ rootValue, _ displayText, _ 3) End If Next End Sub
See Also
Reference
Category
CategoryList
CategoryValueCollection
CategoryInfos
KeyValue
GetRelatedCategories
GetRelatedCategories
Roots
Send
TModelKey
UddiConnection
InquireUrl
ExtensionsUrl
Concepts
Microsoft.Uddi Assembly
Finding Categorization Schemes
Specifying Access Points