- . File-New WebSite ASP.NET Web Setvice (. 5.1).
. 5.1. -
- :
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService]
public class Service: System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
(. 5.2).
. 5.2. -
HelloWorld , (. 5.3).
. 5.3.
- , - .
2. Web- . Web- ASP.NET ASP.NET Web Servce. , :
1) Add(). ;
2) Subtract(), ;
3) Multply(), ;
4) Dvde(), .
- , , :
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Description="Web-", Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service: System.Web.Services.WebService
{
public Service () {
}
[WebMethod (Description="")]
public int Add(int x, int y)
{ return x + y; }
[WebMethod (Description="")]
public int Substract(int x, int y)
{ return x - y; }
[WebMethod (Description="")]
public int Multiply(int x, int y)
{ return x * y; }
[WebMethod (Description="")]
public int Divide(int x, int y)
{ return x / y; }
}
, Web- (. 5.4).
. 5.4. -
, - (. 5.5).
|
|
. 5.5. -
- =10, =10, . 5.6.
. 5.6. -
. 5. 6 , 20. , - - . (. 5.7).
. 5.7. - -
2 , . :
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 171px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br /> <br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br /> <br />
<asp:Button ID="Button1" runat="server" Text="" onclick="Button1_Click" />
<br /> <br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
- . Soluton Explorer Add Web Reference. ³ Add Web Reference (. 5. 8).
. 5. 8. -
URL Web- Go. ϳ , , ' Web Reference Name (, webalc) Add Reference. Web- (. 5.9) ᒺ - Web-.
. 5.9. - -
䳿 -.
protected void Button1_Click(object sender, EventArgs e)
{
webcalc.Service calc = new webcalc.Service();
Label1.Text =Convert.ToString(calc.Multiply(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)));
}
, . 5.10.
. 5.10. -
3. Web- . - .
|
|
using System;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Name="bd", Description="- ", Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service: System.Web.Services.WebService
{
public Service () {
}
string strConn = "Data Source=KATYAN\\SQLEXPRESS;Initial Catalog=tovar;Integrated Security=True";
[WebMethod (MessageName="GetOrders", Description="- ", CacheDuration=600)]
public DataSet GetCustOrders()
{
SqlConnection con = new SqlConnection(strConn);
string sql = "select * from tovar";
SqlDataAdapter mydat=new SqlDataAdapter(sql,strConn);
DataSet ds = new DataSet();
mydat.Fill(ds);
return ds;
}
}
, -.
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns= "False" DataKeyNames="kod_tov" >
<Columns>
<asp:BoundField DataField="nazv" HeaderText="nazv" SortExpression="nazv" />
<asp:BoundField DataField="gost" HeaderText="gost" SortExpression="gost" />
<asp:BoundField DataField="kod_tov" HeaderText="kod_tov" InsertVisible="False"
ReadOnly="True" SortExpression="kod_tov" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
- (. 5. 11).
. 5. 11. -
䳿 - .
protected void Page_Load(object sender, EventArgs e)
{
localhost.bd ser = new localhost.bd();
GridView1.DataSource = ser.GetCustOrders();
GridView1.DataBind();
}
. 5. 12.
. 5. 12. - -
˲
1. . -, . , . . Microsoft ASP.NET 4 # 2010 , 4- . .: , 2011. 1424.
2. . . . -, .: , 2010. 256.
3. . . - ASP.NET. .: , 2007. 640.
4. . Microsoft ASP.NET 2.0. . / . . .: ; .:, 2008. 592 .
5. ASP.NET. , 2007. 238 .
6. . . ASP.NET. . .: , 2002. 512 .
1. . . #. .: -, 2007. 432.
2. . . # . .: -, 2009. 320 .
3. . . #. . - .: -, 2008. 544
4. . . # . NET. . .: ϳ, 2004. 796.
1. : http://www.gotdotnet.ru , . NET Framework.
|
|
2. : http://msdn.microsoft.com Microsoft.
3. : http://www.intuit.ru
㳿 6.050103 (4 7 ) / .. , .. // : , 2016. 88 .
: ..., . ..
..., . ..
ϳ
. .
.
.
. , 2.