Appendix E: Using PERL to Access Web Services


Microsoft provides a Beta version of an API that allows you to interact with a UDDI Web site using an application or Web page that you create. The example provided in this appendix illustrates how to use the API to interact with Microsoft’s UDDI Web site. The C# code is put into a Windows GUI, but it easily could have been put inside an ASP.NET page or a command line application.

First, download the SDK from the location mentioned in Appendix B, and install it according to the instructions provided on Microsoft’s Web site. Create a new C# Windows application, and to utilize the functionality in the SDK you need to add a reference to the Microsoft.Uddi.Sdk.dll that came with the download. This is done by creating a new project in Visual Studio.NET and going to the “Project” menu and selecting “Add Reference.” Then use the “Browse” option to select the dll. Figure F.1 shows the dialogue.

click to expand
Figure F.1: Adding a reference to a project within Visual Studio.NET.

Create a Windows application that has a button, a text box, and a couple of labels. Figure F.2 shows how you might want the GUI to appear for the UDDI. Note that in this image the GUI has already made the call to the UDDI Web site.

click to expand
Figure F.2: How the GUI for the UDDI SDK example in this appendix may appear.

Most of the important code that occurs in this example is found within the “Click Event” of the button in the upper right corner, and this is the following example. The first step is to tell the code where the inquire URL resides for this particular UDDI implementation. In the case of Microsoft’s UDDI Web site, that URL is http://uddi.microsoft.com/inquire.

The next step involves creating a FindBusiness object. This is the object that actually makes the request and receives the data. The next step sets the Name attribute for the FindBusiness object so the request knows what information to ask the UDDI site for. Then a BusinessList object is created and this is a result set for the UDDI request.

To get all the results, you need to move through the BusinessList object myBusiness as if it were a result set from a database. The first piece of data to request from the object is the Name and Descriptions of the company we ask for information about. Then there is a loop that displays all the keys and descriptions for the entries of each company. These values are all appended to the String Results, and once the loops are complete all the information in Results gets sent to the label uddiDisplay.

    private void button1_Click(object sender, System.EventArgs e)     {       try          {          //Call the UDDI repository          Inquire.Url = "http://uddi.microsoft.com/inquire";          //Create a find business object          FindBusiness myFindBusiness = new FindBusiness();          myFindBusiness.Name = businessEntry.Text;          BusinessList myBusinessList = myFindBusiness.Send();          entryCount.Text =          myBusinessList.BusinessInfos.Count.ToString();          if (myBusinessList.Truncated ==           Microsoft.Uddi.Api.TruncatedEnum.True)             ErrorBar.Text = "Results are truncated";             String Results = null;             if (myBusinessList.BusinessInfos.Count > 0)             {             Results += myBusinessList.BusinessInfos[0].Name;             Results +=  "\n" +             myBusinessList.BusinessInfos[0].Descriptions[0].Text+"\n";             Results += "\n\n";             }             for (int j=0;                  j<myBusinessList.BusinessInfos[0].ServiceInfos.Count;                  j++)             {             Results += "Name: ";             Results+=                 myBusinessList.BusinessInfos[0].ServiceInfos[j].Name +                  "\n";             Results += "BusinessKey: ";             Results +=             myBusinessList.BusinessInfos[0].ServiceInfos[j].BusinessKey             + "\n";             Results += "ServiceKey: ";             Results +=             myBusinessList.BusinessInfos[0].ServiceInfos[j].ServiceKey             + "\n";             Results += "\n\n\n";             ErrorBar.Text = "Count: " + j;             }             //display value of Results             uddiDisplay.Text = Results;             }          catch (UddiException error)          {          ErrorBar.Text = " " + error.Number + " "          + error.Message;          }          catch (Exception error)          {          ErrorBar.Text = error.Message;          }     }

The beauty of this SDK is that you could write an application that searches for an appropriate Web Service and then automatically creates the proxy and you then have access to its method. This code also allows you to create Web pages internally for your corporation that can search the UDDI repository without your users having to figure out which one your corporation supports.




Cross-Platform Web Services Using C# and Java
Cross-Platform Web Services Using C# & JAVA (Charles River Media Internet & Web Design)
ISBN: 1584502622
EAN: 2147483647
Year: 2005
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net