Creating a Web Service MethodSee Also
Creating Web Services in Managed Code | WebMethodAttribute Class
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included as placeholders.]When you create a Web Service in managed code, you indicate the methods that are available through that Web Service by placing the WebMethod attribute before the method declaration of a Public method. Private methods cannot serve as the entry point for a Web Service although they can be in the same class and the Web Service code can call them. The WebMethod attribute must be applied to each public method that is available as part of the Web Service. For more information, see Defining Web Service Methods.The procedures below assume that you are working with public methods of a class that is the implementation of a Web Service. For more information, see Code Model for Web Services in Managed Code.To create a Web Service method Select your. asmx file (for example, Service1.asmx) in Solution Explorer. On the View menu, click Code to view the code-behind file. Alternatively, right-click your .asmx file in Solution Explorer and then click View Code on the shortcut menu. 
Note   Solution Explorer hides code-behind files by default. Click Show All Files in the Solution Explorer toolbar to see hidden files. Or, on the Project menu, click Show All Files.
The .asmx file specifies the class that is the implementation of the Web Service in the Class property of the .asmx file's WebService processing directive. Following is an example: ' Visual Basic
<%@ WebService Language="vb" Codebehind="Service1.asmx.vb" Class="WebService1.Service1" %>// C#
<%@ WebService Language="c#" Codebehind="Service1.asmx.cs" Class="WebService1.Service1" %>
If you rename the class, be sure to change the class name in the Class property of the WebService directive as well. Add a public method to the class specified in the Class property of the .asmx file's WebService processing directive as shown below: 
' Visual Basic
Public Class Service1
    Inherits System.Web.Services.WebService
    <WebMethod()> _
    Public Function ConvertTemperature(ByVal dFahrenheit As Double) As Double
        ConvertTemperature = ((dFahrenheit - 32) * 5) / 9
    End Function
End Class// C#
public class Service1 : System.Web.Services.WebService

    [WebMethod()]
    public double ConvertTemperature(double dFahrenheit)
    {
       return ((dFahrenheit - 32) * 5) / 9;
    }
}
Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the Web Service. For more information, see Code Model for Web Services in Managed Code. 

解决方案 »

  1.   

    多谢两位!
    [STAThread]
    这个又有什么用呢?
      

  2.   

       我想问一下,我用的vs.net是beta2的,我的msdn怎么装上去!我每次求帮助的时候总是
    要我放入光盘这样太麻烦了!
      

  3.   

    把相应盘下的Msdn文件复制到你的硬盘上,当它要你放入光盘时,让它指向你的硬盘对应的它要打开的目录位置,就可以了
    [STAThread]的StATHread是一种Attribute,是STATHreadAttribute的缩写,表示线程的访问,
    就我看常见于Main()方法