Finding Categorization Schemes
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 all the categorization schemes that are used on a UDDI server.
Purpose
This topic shows how to find all the categorization schemes that are used on a UDDI server. After finding the categorization schemes, you can then find the root categories and other related categories of these categorization schemes. For more information see Finding Root Categories.
Prerequisites and Requirements
This example requires the following components:
.NET Framework 2.0.
Visual Studio.NET 2003 or later.
A reference to the Microsoft.Uddi Assembly.
A valid UddiConnection object with an inquiry URL. For more information, see Initializing a Connection.
This example also requires the following namespaces:
Example Code
The following Visual C# example shows how to find the categorization schemes on a UDDI server.
static void GetCategorizationSchemesExample( UddiConnection validConnection,
StringBuilder displayText )
{
FindTModel getTModel = new FindTModel();
getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes,
"categorization",
"Categorization (taxonomy)" );
TModelList tModelListResult = null;
try
{
tModelListResult = getTModel.Send( validConnection);
}
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;
}
foreach( TModelInfo tModelItem in tModelListResult.TModelInfos )
{
displayText.Append( "\r\n" + tModelItem.Name.Text );
}
}
The following Visual Basic .NET example shows how to find the categorization schemes on a UDDI server.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _
ByVal displayText As StringBuilder)
Dim getTModel As New FindTModel
getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _
"categorization", _
"Categorization (taxonomy)")
Dim tModelListResult As TModelList
Try
tModelListResult = getTModel.Send(validConnection)
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 tModelItem As TModels.TModelInfo
For Each tModelItem In tModelListResult.TModelInfos
displayText.Append(vbCrLf + tModelItem.Name.Text)
Next
End Sub
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 StringBuilder object. This object contains information about categorization schemes.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { }
Create an instance of the FindTModel class. This object will be used to create the message that is sent to the UDDI server to get the categorization schemes.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); }
Using the Add method, set the CategoryBag property of the FindTModel object to a specified category reference.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)" ); }
Create a TModelList variable and initialize it to null. This object will contain the results of the message from the UDDI server.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)" ); TModelList tModelListResult = null; }
Transmit the request to the UDDI server by using the Send method with the UddiConnection object passed into the method. The TModelList variable receives the results of the request.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)" ); TModelList tModelListResult = null; tModelListResult = getTModel.Send( validConnection); }
Handle any exceptions that might 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 GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)" ); TModelList tModelListResult = null; try { tModelListResult = getTModel.Send( validConnection); } 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; } }
Iterate through the collection in the TModelInfos property to get information about the categorization schemes. In this example, the name of each categorization scheme is added to the StringBuilder object that displays information about categorization schemes.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)" ); TModelList tModelListResult = null; try { tModelListResult = getTModel.Send( validConnection); } 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; } foreach( TModelInfo tModelItem in tModelListResult.TModelInfos ) { displayText.Append( "\r\n" + tModelItem.Name.Text ); } }
Optional. To find the root categories of each categorization scheme, you can create an optional method that finds the root categories. For more information about creating a method that finds root categories, see Finding Root Categories. This example calls the optional method for the ntis-gov:naics:2002 categorization scheme only.
static void GetCategorizationSchemesExample( UddiConnection validConnection, StringBuilder displayText ) { FindTModel getTModel = new FindTModel(); getTModel.CategoryBag.Add( CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)" ); TModelList tModelListResult = null; try { tModelListResult = getTModel.Send( validConnection); } 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; } foreach( TModelInfo tModelItem in tModelListResult.TModelInfos ) { if("ntis-gov:naics:2002" == tModelItem.Name.Text) { displayText.Append( "\r\n" + tModelItem.Name.Text ); GetRootCategoriesExample(validConnection, tModelItem, displayText); } } }
Implementation Steps In Visual Basic .NET
Create a method that accepts the following parameters:
A valid UddiConnection object.
A StringBuilder object. This object contains the information about the categorization schemes.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) End Sub
Create an instance of the FindTModel class. This object creates the message that is sent to the UDDI server to get the categorization schemes.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel End Sub
Using the Add method, set the CategoryBag property of the FindTModel object to a specified category reference.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _ "categorization", _ "Categorization (taxonomy)") End Sub
Create a TModelList variable that will contain the results of the message from the UDDI server.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _ "categorization", _ "Categorization (taxonomy)") Dim tModelListResult As TModelList End Sub
Transmit the request to the UDDI server by using the Send method with the UddiConnection object passed into the method. The TModelList variable receives the results of the request.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _ "categorization", _ "Categorization (taxonomy)") Dim tModelListResult As TModelList tModelListResult = getTModel.Send(validConnection) End Sub
Handle any exceptions that might 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 GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _ "categorization", _ "Categorization (taxonomy)") Dim tModelListResult As TModelList Try tModelListResult = getTModel.Send(validConnection) 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
Iterate through the collection in the TModelInfos property to get information about the categorization schemes. In this example, the name of each categorization scheme is added to the StringBuilder object that displays information about categorization schemes.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _ "categorization", _ "Categorization (taxonomy)") Dim tModelListResult As TModelList Try tModelListResult = getTModel.Send(validConnection) 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 tModelItem As TModels.TModelInfo For Each tModelItem In tModelListResult.TModelInfos displayText.Append(vbCrLf + tModelItem.Name.Text) Next End Sub
Optional. To find the root categories of each categorization scheme, you can create an optional method that finds the root categories. For more information about creating a method that finds root categories, see Finding Root Categories. This example calls the optional method for the ntis-gov:naics:2002 categorization scheme only.
Sub GetCategorizationSchemesExample(ByVal validConnection As UddiConnection, _ ByVal displayText As StringBuilder) Dim getTModel As New FindTModel getTModel.CategoryBag.Add(TModels.CommonCanonical.UddiOrgTypes, _ "categorization", _ "Categorization (taxonomy)") Dim tModelListResult As TModelList Try tModelListResult = getTModel.Send(validConnection) 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 tModelItem As TModels.TModelInfo For Each tModelItem In tModelListResult.TModelInfos If tModelItem.Name.Text = "ntis-gov:naics:2002" Then displayText.Append(vbCrLf + tModelItem.Name.Text) GetRootCategoriesExample(validConnection, tModelItem, displayText) End If Next End Sub
See Also
Reference
FindTModel
InquireUrl
ExtensionsUrl
UddiConnection
CategoryBag
Send
TModelInfos
Name