Microsoft KB Archive/833380

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

Article ID: 833380

Article Last Modified on 4/29/2007

-

APPLIES TO


 * Microsoft Web Services Enhancements for Microsoft .NET 1.1
 * Microsoft Visual C# .NET 2003 Standard Edition

-







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
 * Requirements
 * Create an XML Web service
 * Register programmatically the XML Web service with your internal UDDI server
 * Create a Console Application project
 * Add code to specify your internal UDDI server
 * Add code to publish your XML Web service
 * View the complete code listing (Class1.cs)
 * Verify that you have registered the XML Web service
 * REFERENCES



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
 Start Visual Studio .NET 2003. On the File menu, point to New, and then click Project.

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

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

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

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
<ol> Start Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project.

The New Project dialog box appears.</li> Under Project Types, click Visual C# Projects.</li> Under Templates, click Console Application.</li> In the Name box, type UDDI_Publish_App_CS, and then click OK.

By default, the Class1.cs file is created.</li> On the Project menu, click Add Reference.

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

The Select Component dialog box appears.</li> 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.</li> Click Microsoft.Uddi.dll, and then click Open.</li> <li>Click OK to add the assembly as a project reference to your project.</li> <li> Locate the following code in the Class1.cs file: using System; </li> <li> 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; </li></ol>

back to the top

Add code to specify your internal UDDI server
<ol> <li> Locate the following code in the Class1.cs file: static void Main(string[] args) { </li> <li> 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  with the name of the Web server that you specified in step 5 of the &quot;Create an XML Web service&quot; section of this article. UddiConnection uc=new UddiConnection; uc.PublishUrl = &quot;https://localhost/uddi/publish.asmx&quot;; </li></ol>

back to the top

Add code to publish your XML Web service
<ol> <li> 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  with the name of the Web server that you specified in step 5 of the &quot;Create a Console Application project&quot; section of this article: // Create a tModel. SaveTModel stm = new SaveTModel; TModel t=new TModel(&quot;Insert URN here&quot;); t.Descriptions.Add(&quot;Insert Description here&quot;,&quot;en&quot;); t.OverviewDoc.OverviewUrl=&quot;http://<ServerName>/SalesReportUSA/SalesReport.asmx?wsdl&quot;; stm.TModels.Add(t); stm.TModels[0].CategoryBag.Add(&quot;uuid:c1acf26d-9672-4404-9d70-39b756e62ab4&quot;,&quot;wsdlSpec&quot;,&quot;uddi-org:types&quot;); string sTModelKey = &quot;&quot;; // 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; } </li> <li> 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  with the name of the Web server that you specified in step 5 of the &quot;Create an XML Web service&quot; section of this article. // Create a business entry. SaveBusiness sb = new SaveBusiness; BusinessEntity be=new BusinessEntity(&quot;Insert Business Name here&quot;); be.Descriptions.Add(&quot;Insert Description here&quot;,&quot;en&quot;); sb.BusinessEntities.Add(be); // Create a business service. BusinessService bs=new BusinessService(&quot;Insert Service Name here&quot;); bs.Descriptions.Add(&quot;Insert Description of Service here&quot;,&quot;en&quot;); sb.BusinessEntities[0].BusinessServices.Add(bs); // Create a binding template. BindingTemplate bt=new BindingTemplate; bt.AccessPoint.Text = &quot;http://ServerName/SalesReportUSA/SalesReport.asmx&quot;; 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(&quot;Insert Description here&quot;,&quot;en&quot;); 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; } </li></ol>

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 description for Class1. ///    class Class1 {       ///         /// The main entry point for the application. ///        [STAThread] static void Main(string[] args) {        UddiConnection uc=new UddiConnection; uc.PublishUrl = &quot;https://localhost/uddi/publish.asmx&quot;;

// Create a tModel. SaveTModel stm = new SaveTModel; TModel t=new TModel(&quot;Insert URN here&quot;); t.Descriptions.Add(&quot;Insert Description here&quot;,&quot;en&quot;); t.OverviewDoc.OverviewUrl=&quot;http://localhost/SalesReportUSA/SalesReport.asmx?wsdl&quot;; stm.TModels.Add(t); stm.TModels[0].CategoryBag.Add(&quot;uuid:c1acf26d-9672-4404-9d70-39b756e62ab4&quot;,&quot;wsdlSpec&quot;,&quot;uddi-org:types&quot;); string sTModelKey = &quot;&quot;; // 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(&quot;Insert Business Name here&quot;); be.Descriptions.Add(&quot;Insert Description here&quot;,&quot;en&quot;); sb.BusinessEntities.Add(be); //Create a business service. BusinessService bs=new BusinessService(&quot;Insert Service Name here&quot;); bs.Descriptions.Add(&quot;Insert Description of Service here&quot;,&quot;en&quot;); sb.BusinessEntities[0].BusinessServices.Add(bs); //Create a binding template. BindingTemplate bt=new BindingTemplate; bt.AccessPoint.Text = &quot;http://localhost/SalesReportUSA/SalesReport.asmx&quot;; 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(&quot;Insert Description here&quot;,&quot;en&quot;); 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

<div class="references_section">