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)
SUMMARYTo 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: - Create the XML Web service that you want to publish.
- Write the code to specify your internal UDDI server.
- Write the code to create the data that you want to publish.
- 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 TASKINTRODUCTIONThis 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 topRequirementsThis
article assumes that you are familiar with the following topics:
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 topCreate 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://ServerName/SalesReportUSA.
Note ServerName is a
placeholder for the name of your Web server. - Click OK.
By default, the
Service1.asmx file is created. - In Solution Explorer, right-click
Service1.asmx, and then click
Rename.
- Type SalesReport.asmx instead of the
selected text, and then press ENTER.
- In Solution Explorer, right-click
SalesReport.asmx, and then click View
Code.
- 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;
}
}
} - On the Build menu, click Build
SalesReportUSA.
- Quit Visual Studio .NET 2003.
back to the topRegister programmatically the XML Web service with your internal UDDI registryThe 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 topCreate a Console Application project- 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 Console
Application.
- In the Name box, type
UDDI_Publish_App_CS, and then click
OK.
By default, the Class1.cs file is
created. - On the Project menu, click Add
Reference.
The Add Reference dialog box
appears. - On the .NET tab, click
System.Web.Services.dll under Component Name,
and then click Select.
- Click Browse.
The Select
Component dialog box appears. - 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. - Click Microsoft.Uddi.dll, and then click
Open.
- Click OK to add the assembly as a project
reference to your project.
- Locate the following code in the Class1.cs file:
using System; - 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 topAdd code to specify your internal UDDI server- Locate the following code in the Class1.cs file:
static void Main(string[] args)
{ - 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 topAdd code to publish your XML Web service- 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;
} - 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 topView 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 topVerify that you have registered the XML Web service- On the Build menu, click Build
UDDI_Publish_App_CS in Visual Studio .NET 2003.
- 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
topREFERENCES 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: | Major | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbXML kbWebServices kbUDDI kbServer kbIDEProject kbProgramming kbDiscovery kbSample kbcode kbHOWTOmaster KB833380 kbAudDeveloper |
---|
|
|
©2004 Microsoft Corporation. All rights reserved.
|
|