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.
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.
解决方案 »
- ListView列标题上如何添加鼠标右键菜单
- C#调用非托管dll运行时随机报System.AccessViolationException
- 再送五十分,求同一机子不重复登录方法WINFROM
- winform中datagridview列的显示问题~~~
- 各位大侠请问 C#怎么将汉字转换成16进制啊?
- 请教:c#中的分布式事务处理?
- 救命啊!新手需要:::关于C#中关于MD5还有Kerberos public key
- 求一条sql语句
- 大家帮忙
- C# 合并word文档,其中一个word有图片但合并后只有一个有红色叉的白框
- 如果微软继续跟进Java,他们迟早会把它消灭掉,而Java其实不过是Windows和Internet之战的牺牲品!!!
- Framework 分发包
[STAThread]
这个又有什么用呢?
要我放入光盘这样太麻烦了!
[STAThread]的StATHread是一种Attribute,是STATHreadAttribute的缩写,表示线程的访问,
就我看常见于Main()方法