This documentation is archived and is not being maintained.

WebServiceAttribute Class

Used to add additional information to an XML Web service, such as a string describing its functionality.

For a list of all members of this type, see WebServiceAttribute Members.

System.Object
   System.Attribute
      System.Web.Services.WebServiceAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Class)>
NotInheritable Public Class WebServiceAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class)]
public sealed class WebServiceAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class)]
public __gc __sealed class WebServiceAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Class)
class WebServiceAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The WebServiceAttribute is not required for an XML Web service to be published and executed. You can use the WebServiceAttribute to specify a name for the XML Web service that is not restricted by the rules for a common language runtime identifier, which is used in the service description and the Service help page for the XML Web service.

An XML Web service should change its default XML namespace before the it is made public. Each XML Web service needs a unique XML namespace to identify it so that client applications can distinguish it from other services on the Web. http://tempuri.org/ is available for XML Web services that are under development, but published XML Web services should use a more permanent namespace.

Your XML Web service should be identified by a XML namespace that you control. For example, you could use your company's Internet domain name as part of the XML namespace. Although many XML Web service XML namespaces look like URLs, they need not point to an actual resource on the Web. (XML Web service XML namespaces are URIs.) For XML Web services created using ASP.NET, the default XML namespace can be changed using Namespace property.For more information about using attributes, see Extending Metadata Using Attributes.

Example

[Visual Basic, C#] The following example sets the Description property of the WebServiceAttribute to " Common Server Variables " and sets the XML namespace to http://www.microsoft.com/ .

[Visual Basic] 
<%@ WebService Language="VB" Class= "ServerVariables"%>
 
Imports System
Imports System.Web.Services

<WebService(Description := "Common Server Variables", _
 Namespace := "http://www.contoso.com/")> _
Public Class ServerVariables
    Inherits WebService 
    
    <WebMethod(Description := "Obtains the Computer Machine Name", _
        EnableSession := False)> _
    Public Function GetMachineName() As String
        
        Return Server.MachineName
    End Function
End Class
 

[C#] 
<%@ WebService Language="C#" Class= "ServerVariables"%>
 
 using System;
 using System.Web.Services;
 
 [ WebService(Description="Common Server Variables",Namespace="http://www.contoso.com/")]
 public class ServerVariables: WebService {
 
 
    [ WebMethod(Description="Obtains the Server Computer Name",EnableSession=false)]
    public string GetMachineName() {
       return Server.MachineName;
    }   
 }
 

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.Services

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web.Services (in System.Web.Services.dll)

See Also

WebServiceAttribute Members | System.Web.Services Namespace | WebService | WebMethodAttribute | SoapDocumentMethodAttribute | SoapDocumentServiceAttribute | SoapRpcMethodAttribute | SoapRpcServiceAttribute

Show: