
C# ПІДРУЧНИКИ / c# / Hungry Minds - ASP.NET Bible VB.NET & C#
.pdf
|
Table 27-1: Disco tool command-line options |
|
|
|
|
|
|
|
|
|
Option |
|
Description |
|
|
|
|
|
|
|
|
|
the tool. |
|
|
|
|
|
|
The Disco tool copies and generates the following files into the folder where you executed the Disco tool or the folder specified by the /out option. Let's look at an example using the Disco tool to locate the Web service description files for our CTemp Web service.
First, let's assume for a moment that we only know the name of the Web server that is hosting our CTemp service, but would like to discover the complete URL to it. We can do this by typing the following at the command prompt:
disco /nosave http://localhost
This command will initiate the discovery process against the local Web server, searching for all discovery documents and related files that are referenced in these discovery documents. Note that we are not saving any of the results yet (using the /nosave option).
When dynamic discovery is enabled at the root of the Web server (the default), the Disco tool will search hierarchically through all Web server folders. Running the previous command against my Web server produces the results shown in Figure 27-1.
Figure 27-1: Using the Disco tool to find Web services
Notice that the Disco tool has listed all the discovery documents it found on the Web server as well as a reference to a single WSDL document for our CTemp Web service. Now that we know the complete URL to the CTemp Web service, let's use the Disco tool one more time to discover information specific to the CTemp Web service. This time, we will save the results to a temporary folder, using the following command:
disco /out=c:\temp http://localhost/ctemp/ctemp.vsdisco
This will initiate the discovery process against the discovery document of the CTemp Web service located on your local Web server. Once again, executing this command on my Web server produces the results shown in Figure 27-2.


or a specific Web service virtual directory on a Web server. In any case, you won't be able to find any Web services using Disco without knowing a URL.
As mentioned previously, UDDI is a more generalized search tool for locating Web services. Using UDDI, you can specify search terms that enable you to pinpoint Web services you wish to use based on company, industry, service type, and many other classifications. Using these more generalized search terms usually results in the listing of specific URLs to which you can locate information about specific Web services, including the WSDL document that you are ultimately searching for.
In this section, we will explore how to find Web services using the interactive UDDI Web site. This Web site provides search forms for locating Web services (and Web service descriptions). To illustrate the search process, we will search for Web services that are published by Microsoft.
Let's start by browsing to the UDDI Web site at http://www.uddi.org. After you get there, click the Find link at the top of the page. This displays the Find page. On this page, choose the Microsoft UDDI node from the list box and click GO. This brings you to the Microsoft UDDI node search page, as shown in Figure 27-3.
Figure 27-3: The Microsoft UDDI Search Page
Notice that the search page provides category -based browsing that enables you to locate Web services based on various company classifications, including ISO 3166 Geographic Taxonomy and Standard Industrial Classification, among others.
In the middle of the page is the Advanced Search form. From here, you can enter text in the Search For text box to perform a custom search of various fields within the database. You can locate Web services in this manner by searching any one of the following field types:
§Business Name: Use this field to search within registered business names. For example, you could search for services provided by IBM.
§Business Location: Use this field to search by geographic location. For example, you could search for companies that provide services within the St. Louis area.
§Service Type By Name: Use this field to search services submitted by a company by the service name.
§Business Identifier: Identifiers are pieces of data that are unique to an individual business, such as the standard D-U-N-S™ Number. There are


Figure 27-5: Microsoft Smart Searching Web Service bindings detail
The interesting information displayed here is supplied by the Access Point link. Note that the URL points to the entry point of two categorized Web service interfaces:
§A Vocabulary service
§A Best Bets service
Each service shares a common URL. Go ahead and click one of the entry point links. By now you know that pointing your browser to an ASMX file will return the ASP.NET Web Service description page. From this page, you can access the WSDL contract, which can be saved to your local hard drive and then interrogated by the wsdl tool to create a Web service proxy class. You will learn more about this process shortly.
Congratulations! You have just located your first Web service from the UDDI business registry! Of course, myriad ways exist to search the registry. Which one you choose depends on what you are looking for and how much information you have related to the Web service.
Caution
If you are not using Visual Studio to build or consume Web services, you will want to become familiar with the facilities provided by the UDDI business registry nodes. Over time, these sites will hopefully provide one-stop shopping for locating high-quality Web services that you can incorporate into your custom solutions.
Although a simple and effective solution for finding Web services, you may encounter some cases in which you cannot use Visual Studio's Web Reference feature, such as when the Web service is not accessible from the machine on which you are using Visual Studio. Under these circumstances, you can use the Web Service Description Language Tool (wsdl.exe) to generate a Web Service client proxy class. We will cover this tool in the next section.
Web Service Interrogation and Proxy Classes
Web service interrogation is the process of examining a Web service description to determine how to interact with the Web service as a consumer. As you have learned, a Web service communicates with consumers using messages encoded in XML and encapsulated in SOAP. You have also seen that these messages can be transported over one of several protocols (such as HTTP, SMTP, and so on). Lastly, the Web service




|
Table 27-3: WSDL tool command-line options |
|
|
|
|
|
|
|
|
|
Option |
|
Description |
|
|
|
|
|
|
|
/u[sername]:username |
|
Specifies the username |
|
|
|
|
|
|
|
|
|
to use when connecting |
|
|
|
|
to a server that requires |
|
|
|
|
authentication. |
|
|
|
|
|
|
|
/? |
|
Displays command |
|
|
|
|
|
|
|
|
|
syntax and options for |
|
|
|
|
the tool. |
|
|
|
|
|
|
The following example illustrates the use of the wsdl tool to generate a proxy class for our CTemp Web service:
VB.NET:
wsdl /l:vb /out:CTempProxy.vb http://localhost/ctemp/ ctemp.asmx?wsdl
C#:
wsdl /l:cs /out:CTempProxy.cs http://localhost/ctemp/ ctemp.asmx?wsdl
This example creates a proxy class in the specified language syntax and saves it to a file named CTempProxy.vb (or CTempProxy.cs, depending on which language you choose). The proxy is generated from the WSDL provided by the URL specified on the command line.
The output of the wsdl tool in the command window should look similar to Figure 27-6.
Figure 27-6: Results of executing the wsdl tool
The following proxy class source code generated by the wsdl tool is for VB.NET: '----------------------------------------------
----------------------
'<autogenerated>
'This code was generated by a tool.
'Runtime Version: 1.0.2914.16
'
'Changes to this file may cause incorrect behavior and will be lost if
'the code is regenerated.
'</autogenerated>
'-----------------------------------------------
---------------------
Option Strict Off
Option Explicit On
Imports System
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
'This source code was auto-generated by wsdl, Version=1.0.2914.16.
'
<System.Web.Services.WebServiceBindingAttribute
(Name:="TempConverterSoap", [Namespace]:="http://mydomain.com/ws/ctemp")> _ Public Class TempConverter
Inherits
System.Web.Services.Protocols.SoapHttpClientProtocol
<System.Diagnostics.DebuggerStepThroughAttribute()> _ Public Sub New()
MyBase.New
Me.Url = "http://jdc7200cte/services/ctemp/ctemp.asmx"
End Sub
<System.Diagnostics.DebuggerStepThroughAttribute(), _ System.Web.Services.Protocols.SoapDocumentMethodAttribute
("http://mydomain.com/ws/ctemp/CTemp", RequestNamespace:=
"http://mydomain.com/ws/ctemp", ResponseNamespace:=
"http://mydomain.com/ws/ctemp", Use:=System.Web.Services.Description.
SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.
SoapParameterStyle.Wrapped)> _
Public Function CTemp(ByVal Temperature As Decimal, ByVal FromUnits As String, ByVal ToUnits As String) As Decimal
Dim results() As Object = Me.Invoke("CTemp",
New Object() {Temperature, FromUnits, ToUnits})
Return CType(results(0),Decimal)
End Function
<System.Diagnostics.DebuggerStepThroughAttribute()> _ Public Function BeginCTemp(ByVal Temperature As Decimal,
ByVal FromUnits As String, ByVal ToUnits As String, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult