Share via


Finding a Business

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

One of the tasks you will do most frequently when working with a UDDI server is to find a business. This topic shows you how to find a specified business from a UDDI server. To find a business, use the FindBusiness class, as shown in the following example.

Example Code

The following example shows you how to use the Visual C# programming language to find a business using a specified UddiConnection object and business name.

public void FindBusinessSample(Microsoft.Uddi.UddiConnection myConn,
string businessName)
{
    try
    {
        Microsoft.Uddi.FindBusiness findBiz = new FindBusiness(businessName);
        BusinessList bizList = findBiz.Send(myConn);
        
        // Display the results of the search. 
        int bizCount = bizList.BusinessInfos.Count;
        
        switch(bizCount)
        {
            case(0):
            {
                Console.WriteLine("No results from the search.");
                return;
            }
            
            case(1):
            {
                Console.WriteLine(String.Concat("There is one business called ", 
                                                 businessName));
                break;
            }    
            
            default:
            {
                Console.WriteLine(String.Concat("There are ",
                                                 bizCount, 
                                                 " businesses called ", 
                                                 businessName,
                                                 "."));
                break;
            }
        }
        
        // Show each business name.
        foreach(BusinessInfo bizInfo in bizList.BusinessInfos)
        {
            foreach(Name bizName in bizInfo.Names)
            {
                Console.WriteLine(bizName.Text);
            }
        }
    }
    
    catch (UddiException uddiEx)
    {
        Console.WriteLine(String.Concat("UDDI error: ", uddiEx.Message));
    }
        
    catch (Exception genEx)
    {
        Console.WriteLine(String.Concat("General exception: ", genEx.Message));
    }
}

The following example shows you how to use the Visual Basic .NET programming language to find a business using a specified UddiConnection object and business name.

Public Sub FindBusinessSample(ByVal myConn As Microsoft.Uddi.UddiConnection, _
ByVal businessName As String)

    Dim findBiz As Microsoft.Uddi.FindBusiness
    Dim bizList As Microsoft.Uddi.BusinessList
    Dim bizCount As Integer
    Dim bizInfo As Microsoft.Uddi.Businesses.BusinessInfo
    Dim bizName As Microsoft.Uddi.Name

    Try
        findBiz = New Microsoft.Uddi.FindBusiness(businessName)
        bizList = findBiz.Send(myConn)


        ' Display the results of the search.
        bizCount = bizList.BusinessInfos.Count

        Select Case bizCount

            Case 0
                Console.WriteLine("No results from the search.")

            Case 1
                Console.WriteLine(String.Concat("There is one business called ", _
                                                businessName))

            Case Else
                Console.WriteLine(String.Concat("There are ", _
                                                bizCount, _
                                                " businesses called ", _
                                                businessName, _
                                                "."))

        End Select

        ' Show each business name.
        For Each bizInfo In bizList.BusinessInfos
            For Each bizName In bizInfo.Names
                Console.WriteLine(bizName.Text)
            Next
        Next

        Catch uddiEx As Microsoft.Uddi.UddiException
            Console.WriteLine(String.Concat("UDDI error: ", uddiEx.Message))

        Catch ex As Exception
            Console.WriteLine(ex.GetType())

    End Try

End Sub

Send comments about this topic to Microsoft.