Saving 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 most common tasks you will perform when publishing to a UDDI server is to save a business. To save a business, use the SaveBusiness class, as shown in the following example.

Be aware how this example demonstrates the ToString method. The resulting string is the exact XML that is sent to the UDDI server by the Send method.

Note

Make a note of the business key that the UDDI server returns in this example. You can use it with the examples in the following topics.

Example Code

The following example shows how to use the C# programming language to create a new business entity on a UDDI server.

using System;

using Microsoft.Uddi;
using Microsoft.Uddi.Businesses;
using Microsoft.Uddi.Services;
using Microsoft.Uddi.TModels;

public class SaveMyBiz
{

    public static void Main(string [] args)
    {
        try 
        {
            // Create a connection to the UDDI server that is to be accessed. Replace the contoso.com placeholder URL with your own UDDI server.
            UddiConnection myConn = new UddiConnection("http://test.uddi.contoso.com/inquire",
                "https://test.uddi.contoso.com/publish");

            // Create authentication credentials for save operation.
            myConn.AuthenticationMode = AuthenticationMode.UddiAuthentication;
            myConn.Username = " *** insert your username *** ";
            myConn.Password = " *** insert your password *** ";

            // Create a named business entity.
            BusinessEntity myBiz = new BusinessEntity();
            myBiz.Names.Add(" *** insert your business name *** ");

            // Use business entity to create an object to save a business.
            SaveBusiness sb = new SaveBusiness(myBiz);

            // Display XML sent to UDDI server.
            Console.WriteLine(sb.ToString());
            Console.WriteLine();

            // Send the save business request.
            BusinessDetail savedBiz = sb.Send(myConn);

            // Interpret the returned business detail to examine the allocated business key.
            Console.WriteLine("Business: " + savedBiz.BusinessEntities[0].Names[0].Text);
            Console.WriteLine("  Allocated key: " + savedBiz.BusinessEntities[0].BusinessKey);
        }
        catch (Microsoft.Uddi.UddiException e)
        {
            Console.WriteLine("UDDI error: " + e.Message);
        }
        catch (Exception gen)
        {
            Console.WriteLine("General exception: {0}", gen.Message);
        }
    }
}
// Use the following commands to compile and run this example after replacing
// "C:\MyUddiAssemblyDirectory\" with the full path to the Microsoft.Uddi assembly.
// To compile: csc.exe /r:C:\MyUddiAssemblyDirectory\microsoft.uddi.dll /out:SaveMyBiz.exe SaveMyBiz.cs
// To run:     SaveMyBiz.exe

Send comments about this topic to Microsoft.