Section 15.9. WebService Attribute

15.9. WebService Attribute

The WebService attribute (not to be confused with the WebMethod attribute or the WebService directive) allows you to add additional information to a web service. The WebService attribute is optional, though VS2005 inserts a default WebService attribute.

Here is the syntax for a WebService attribute:

 [WebService(PropertyName=value)] 

PropertyName is a valid property accepted by the WebService attribute (these are described shortly), and value is the value to be assigned to that property.

If there are multiple WebService properties, separate each property/value pair with a comma within a single set of parentheses as in this example:

 [WebService (Description="A stock ticker using C#.",              Name="StockTicker",              Namespace="www.LibertyAssociates.com")] 

There are three possible properties for a WebService attribute, described in the next three sections.

15.9.1. Description Property

The WebService attribute's Description property assigns a descriptive message to the web service. As with the WebMethod attribute's Description property, the WebService description will be displayed in the web service help page when the page is tested in a browser and will be made available in the SOAP message to any potential consumers of the web service.

15.9.2. Name Property

The name of a web service is displayed at the top of a web service help page when the page is tested in a browser and is made available to any potential consumers.

By default, the name of a web service is the name of the class implementing the web service. The WebService attribute's Name property allows you to change the name. If you glance back at the code listed in Example 15-4, you'll notice the class name is Service .

Prior to adding the WebService attribute, Service was displayed at the top of the test page when the service was run in a browser. After adding the above WebService attribute with the Name property set to StockTicker , that is the name displayed on the test page.

15.9.3. Namespace Property

Each web service has an XML namespace associated with it. An XML namespace allows you to create names in an XML document that are uniquely identified by a Uniform Resource Identifier (URI) . The web service is described using a WSDL document, which is defined in XML. Each WebService attribute must have a unique XML namespace associated with it to ensure it can be uniquely identified by an application.

The default URI of a web service created in VS2005 is http://tempuri.org/. Typically, you will define a new namespace using a unique name, such as a firm's web site. Though the XML namespace often looks like a web site, it does not need to be a valid URL.

In the syntax given above for the WebService attribute, the Namespace property is set to www.LibertyAssociates.com, which happens to be a valid web site URL, though that is not required.



Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

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