Recently these days the task completes, also does not have the important matter, took time to study the webservices knowledge, the feeling is quite interesting, the difficulty is not very big.
First, create a asp.net web site with VS2008
Second, the project right key-> Add New Item->web service the following figure:
will produce WebService.cs and webservice.asmx two files.
To add code to the WebService.cs:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Services;
Using System.Web.Script.Services;
<summary>
Summary description of WebService
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
Note Add the following code//
[ScriptService]
To allow the use of ASP.net AJAX to invoke this Web service from a script, uncomment the downlink.
[System.Web.Script.Services.ScriptService]
public class WebService:System.Web.Services.WebService
{
Public WebService ()
{
If you are using a design component, uncomment it to follow the line
InitializeComponent ();
}
[WebMethod]
public string HelloWorld ()
{
Return to "Hello World";
}
[WebMethod]
public int getsum (int a, int b)
{
int sum = a + b;
return sum;
}
}
Default.aspx page
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script language= "JavaScript" >
function method (obj)
{
document.getElementById ("Txtsum"). Value = obj;
}
function Hello ()
{
Webservice.helloworld (Backmethod);
}
function Getsum ()
{
var a,b;
A = document.getElementById ("Txta"). Value;
b = document.getElementById ("Txtb"). Value;
Try
{
Webservice.getsum (A, B, method);
}
catch (Err)
{
alert (Err.Description);
}
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:scriptmanager id= "ScriptManager1" runat= "Server" >
<Services>
<asp:servicereference inlinescript= "True" path= "Webservice.asmx"/>
</Services>
</asp:ScriptManager>
<input type= "button" id= "Bthello" value= "Hello" onclick= "hello ();"/><br/>
<input type= "text" id= "txta" value= ""/>+
<input type= "text" id= "TXTB" value= ""/>=
<input type= "text" id= "txtsum" value= ""/>
<input type= "button" id= "Btsum" value= "sum" onclick= "getsum ();"/><br/>
</div>
</form>
</body>
You can easily invoke the methods in webservice by using the above methods, and you can return a dataset result set in WebService.
I have to continue to learn webservice knowledge in the back.
If you have a good webservice to learn the information or the site, take out to share, in order to facilitate common learning, exchange.