How to publish an XML Web service to an internal UDDI server by using Visual C# .NET 2003 (833380)



The information in this article applies to:

  • Microsoft Web Services (included with the .NET Framework 1.1)
  • Microsoft Visual C# .NET (2003)

SUMMARY

To publish an XML Web service to an internal UDDI server by using Microsoft Visual C# .NET 2003, you must use the features that are implemented in the Microsoft.Uddi.dll assembly. This assembly is included with the Microsoft Platform Software Development Kit (SDK).

The following steps are a sequential overview of the steps that you must follow:
  1. Create the XML Web service that you want to publish.
  2. Write the code to specify your internal UDDI server.
  3. Write the code to create the data that you want to publish.
  4. Write the code to publish the data.

    This data represents your business.
When you run the code, you can verify that you have successfully published your XML Web service to the internal UDDI server.

IN THIS TASK

INTRODUCTION

This step-by-step article describes how to publish an XML Web service to an internal Universal Description, Discovery, and Integration (UDDI) server by using Visual C# .NET 2003. To do this, you must use the features that are implemented in the Microsoft.Uddi.dll assembly. This assembly is included with the Microsoft Windows Core SDK of the Microsoft Platform SDK.

back to the top

Requirements

This article assumes that you are familiar with the following topics:
  • XML Web services
  • UDDI
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
  • Microsoft Windows 2000, Microsoft Windows XP, or Microsoft Windows Server 2003
  • Microsoft Visual Studio .NET 2003
  • Microsoft Platform SDK
back to the top

Create an XML Web service

  1. Start Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual C# Projects.
  4. Under Templates, click ASP.NET Web Service.
  5. In the Location box, type http://ServerName/SalesReportUSA.

    Note ServerName is a placeholder for the name of your Web server.
  6. Click OK.

    By default, the Service1.asmx file is created.
  7. In Solution Explorer, right-click Service1.asmx, and then click Rename.
  8. Type SalesReport.asmx instead of the selected text, and then press ENTER.
  9. In Solution Explorer, right-click SalesReport.asmx, and then click View Code.
  10. In the SalesReport.asmx.cs file, replace the existing code with the following code:
    using System;
    using System.Web.Services;
    namespace SalesReportUSA
    {
    	[WebService(Namespace="urn:myCompany-com:SalesReport-Interface")]
    	public class SalesReport : System.Web.Services.WebService
    	{
    		[WebMethod]
    		public double GetSalesTotalByRange ( System.DateTime startDate, System.DateTime endDate )
    		{
    			return 5000.00;
    		}   
    	}
    }
  11. On the Build menu, click Build SalesReportUSA.
  12. Quit Visual Studio .NET 2003.
back to the top

Register programmatically the XML Web service with your internal UDDI registry

The following three sections demonstrate the process that you must follow to register programmatically the XML Web service with your internal UDDI registry.

back to the top

Create a Console Application project

  1. Start Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual C# Projects.
  4. Under Templates, click Console Application.
  5. In the Name box, type UDDI_Publish_App_CS, and then click OK.

    By default, the Class1.cs file is created.
  6. On the Project menu, click Add Reference.

    The Add Reference dialog box appears.
  7. On the .NET tab, click System.Web.Services.dll under Component Name, and then click Select.
  8. Click Browse.

    The Select Component dialog box appears.
  9. In the Select Component dialog box, locate the Microsoft.Uddi.dll assembly on your computer.

    Typically, this assembly is located in the C:\Program Files\Microsoft SDK\Bin folder.
  10. Click Microsoft.Uddi.dll, and then click Open.
  11. Click OK to add the assembly as a project reference to your project.
  12. Locate the following code in the Class1.cs file:
    using System;
  13. Add the following code after the code that you located in the previous step to use the appropriate namespaces:
    using System.Web.Services;
    using Microsoft.Uddi;
    using Microsoft.Uddi.TModels;
    using Microsoft.Uddi.Businesses;
    using Microsoft.Uddi.Services;
back to the top

Add code to specify your internal UDDI server

  1. Locate the following code in the Class1.cs file:
    static void Main(string[] args)
    {
  2. Add the following code after the code that you located in the previous step to specify your internal UDDI server.

    Note Use an appropriate URL in the following code for your internal UDDI server. Also, you must make sure that the Web site for your internal UDDI server is a security-enhanced Web site.

    Note In the following code, replace ServerName with the name of the Web server that you specified in step 5 of the "Create an XML Web service" section of this article.
    UddiConnection uc=new UddiConnection();
    uc.PublishUrl = "https://localhost/uddi/publish.asmx";
back to the top

Add code to publish your XML Web service

  1. Add the following code after the code that you added in the previous section to publish the Web Services Description Language (WSDL) files that are associated with your XML Web service to your internal UDDI server as a technical model (tModel).

    Note In the following code, replace ServerName with the name of the Web server that you specified in step 5 of the "Create a Console Application project" section of this article:
    // Create a tModel.
    SaveTModel stm = new SaveTModel();
     
    TModel t=new TModel("Insert URN here");
    t.Descriptions.Add("Insert Description here","en");
    t.OverviewDoc.OverviewUrl="http://<ServerName>/SalesReportUSA/SalesReport.asmx?wsdl"; 
    stm.TModels.Add(t);
     
    stm.TModels[0].CategoryBag.Add("uuid:c1acf26d-9672-4404-9d70-39b756e62ab4","wsdlSpec","uddi-org:types");
    string sTModelKey = "";
     
    // Send the tModel data to the UDDI server.
    try
    {
       TModelDetail tmd = stm.Send(uc);
       sTModelKey = tmd.TModels[0].TModelKey;                
    }
    catch (UddiException ue)
    {
       Console.WriteLine(ue.Message);
       return;
    }
    catch (Exception e)
    {
       Console.WriteLine(e.Message);
       return;
    }
  2. Add the following code after the code that you added in the previous step to publish your business entry to your internal UDDI server.

    Note In the following code, replace ServerName with the name of the Web server that you specified in step 5 of the "Create an XML Web service" section of this article.
    // Create a business entry.
    SaveBusiness sb = new SaveBusiness();
    BusinessEntity be=new BusinessEntity("Insert Business Name here");
    be.Descriptions.Add("Insert Description here","en");
    sb.BusinessEntities.Add(be);
     
    // Create a business service.
    BusinessService bs=new BusinessService("Insert Service Name here");
    bs.Descriptions.Add("Insert Description of Service here","en");
    sb.BusinessEntities[0].BusinessServices.Add(bs);
     
    // Create a binding template.
    BindingTemplate bt=new BindingTemplate();
    bt.AccessPoint.Text = "http://ServerName/SalesReportUSA/SalesReport.asmx";
    bt.AccessPoint.UrlType=  Microsoft.Uddi.UrlType.Http; 
    sb.BusinessEntities[0].BusinessServices[0].BindingTemplates.Add(bt);
     
    // Create the tModel instance information.
    TModelInstanceInfo ti=new TModelInstanceInfo();
    ti.Descriptions.Add("Insert Description here","en");
    ti.TModelKey=sTModelKey;
    sb.BusinessEntities[0].BusinessServices[0].BindingTemplates[0].TModelInstanceInfos.Add(ti);
     
    // Send the business entry data to the UDDI server.
    try
    {
       BusinessDetail bd = sb.Send(uc);
       // Show the XML representation of your business entry.
       Console.WriteLine(bd);
    }
    catch (UddiException ue)
    {
       Console.WriteLine(ue.Message);
       return;
    }
    catch (Exception e)
    {
       Console.WriteLine(e.Message);
       return;
    }
back to the top

View the complete code listing (Class1.cs)

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

namespace UDDI_Publish_App_CS
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
         UddiConnection uc=new UddiConnection();
         uc.PublishUrl = "https://localhost/uddi/publish.asmx";

         // Create a tModel.
         SaveTModel stm = new SaveTModel();
 
         TModel t=new TModel("Insert URN here");
         t.Descriptions.Add("Insert Description here","en");
         t.OverviewDoc.OverviewUrl="http://localhost/SalesReportUSA/SalesReport.asmx?wsdl"; 
         stm.TModels.Add(t);
 
         stm.TModels[0].CategoryBag.Add("uuid:c1acf26d-9672-4404-9d70-39b756e62ab4","wsdlSpec","uddi-org:types");
         string sTModelKey = "";
 
         // Send the tModel data to the UDDI server.
         try
         {
            TModelDetail tmd = stm.Send(uc);
            sTModelKey = tmd.TModels[0].TModelKey;                
         }
         catch (UddiException ue)
         {
            Console.WriteLine(ue.Message);
            return;
         }
         catch (Exception e)
         {
            Console.WriteLine (e.Message);
            return;
         }

         // Create a business entry.
         SaveBusiness sb = new SaveBusiness();
         BusinessEntity be=new BusinessEntity("Insert Business Name here");
         be.Descriptions.Add("Insert Description here","en");
         sb.BusinessEntities.Add(be);
 
         //Create a business service.
         BusinessService bs=new BusinessService("Insert Service Name here");
         bs.Descriptions.Add("Insert Description of Service here","en");
         sb.BusinessEntities[0].BusinessServices.Add(bs);
 
         //Create a binding template.
         BindingTemplate bt=new BindingTemplate();
         bt.AccessPoint.Text = "http://localhost/SalesReportUSA/SalesReport.asmx";
         bt.AccessPoint.UrlType=  Microsoft.Uddi.UrlType.Http; 
         sb.BusinessEntities[0].BusinessServices[0].BindingTemplates.Add(bt);
 
         //Create the tModel instance information.
         TModelInstanceInfo ti=new TModelInstanceInfo();
         ti.Descriptions.Add("Insert Description here","en");
         ti.TModelKey=sTModelKey;
         sb.BusinessEntities[0].BusinessServices[0].BindingTemplates[0].TModelInstanceInfos.Add(ti);
 
         // Send the business entry data to the UDDI server.
         try
         {
            BusinessDetail bd = sb.Send(uc);
            // Show the XML representation of your business entry.
            Console.WriteLine(bd);
         }
         catch (UddiException ue)
         {
            Console.WriteLine(ue.Message);
            return;
         }
         catch (Exception e)
         {
            Console.WriteLine (e.Message);
            return;
         }
         }
         }
}
back to the top

Verify that you have registered the XML Web service

  1. On the Build menu, click Build UDDI_Publish_App_CS in Visual Studio .NET 2003.
  2. On the Debug menu, click Start to run the application.

    You receive a console window that contains the XML representation of your business.

    Note When you are prompted for authentication credentials, provide the user name and the password of a user who has permission to publish data to your internal UDDI server.
back to the top

REFERENCES

For additional information about programming the Web with XML Web services, visit the following Microsoft Developer Network (MSDN) Web site:For additional information about UDDI, visit the following MSDN Web site:For additional information about using UDDI at run time, visit the following MSDN Web site:For additional information about UDDI services, visit the following Microsoft Web site:back to the top

Modification Type:MajorLast Reviewed:10/10/2006
Keywords:kbXML kbWebServices kbUDDI kbServer kbIDEProject kbProgramming kbDiscovery kbSample kbcode kbHOWTOmaster KB833380 kbAudDeveloper