软件新技术WEB实验报告文档格式.docx
《软件新技术WEB实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《软件新技术WEB实验报告文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
![软件新技术WEB实验报告文档格式.docx](https://file1.bdocx.com/fileroot1/2022-11/21/b45c0a8e-2027-408b-80a8-7df1aa53d495/b45c0a8e-2027-408b-80a8-7df1aa53d4951.gif)
)]
publicintSubtract(intx,inty)
{
returnx-y;
}
[WebMethod(Description="
返回两个整数的和"
publicintSubtrac(intx,inty)
returnx+y;
[WebMethod(Description="
返回两个整数的积"
publicintSubtra(intx,inty)
returnx*y;
返回两个整数的商"
publicintSubtr(intx,inty)
returnx/y;
在IIS上发布此服务截图:
步骤如下:
以上的WEB服务存放在test_21文件夹中,将该文件夹存放到C:
\inetpub\wwwroot中,
启动IIS管理器,如图:
右击DefaultWebSite添加虚拟目录,如图:
右击test_21,找到管理应用程序,再点击浏览。
跳到如下界面:
点击Service.asmx,继续跳转到如下界面:
例如点击Subtrac
如能成功跳转结果值,则说明发布成功。
下面接着创建可实现对病人住院信息的查询、录入、删除、修改的Web服务。
WEBSERVICE代码如下:
查询病人信息,输入病人姓名"
)]
publicDataTableSubtract(stringxingming)
xingming="
%"
+xingming+"
;
stringsql="
server=.;
database=Patientimform;
user=sa;
pwd=;
"
SqlConnectionstrsql=newSqlConnection(sql);
strsql.Open();
stringserch="
select*fromdbo.patientwhere姓名like'
+xingming+"
'
DataTabletb=newDataTable();
tb.TableName="
guanchenggong"
SqlDataAdapteradp=newSqlDataAdapter(serch,strsql);
adp.Fill(tb);
strsql.Close();
returntb;
添加病人信息"
publicstringAD(stringid,stringsname,intage,stringsex,stringdoctor,stringtypea,stringtypeb)
stringi;
SqlConnectionconn=newSqlConnection("
);
insertintodbo.patientvalues('
+id+"
'
+sname+"
+age+"
+sex+"
+doctor+"
+typea+"
+typeb+"
)"
conn.Open();
SqlCommandcmd=newSqlCommand(sql,conn);
i=cmd.ExecuteNonQuery().ToString();
conn.Close();
returni;
删除病人信息"
publicstringde(stringindexid)
stringts;
deletefromdbo.patientwhere病人编号='
+indexid+"
ts=cmd.ExecuteNonQuery().ToString();
returnts;
更新病人信息"
publicstringup(stringid,stringsname,intage,stringsex,stringdoctor,stringtypea,stringtypeb)
//stringsql="
updatedbo.patientset学号='
+id+"
姓名='
+sname+"
年龄='
+age+"
性别='
+sex+"
医生='
+doctor+"
病症='
+typea+"
类别='
+typeb+"
+"
where病人编号="
+id;
updatedbo.patientset姓名='
where病人编号='
以上的WEB服务存放在test_22文件夹中,将该文件夹存放到C:
例如:
我们要根据病人姓名来查询病人信息。
点击Subtract
跳转到如下界面:
点击调用,显示要查询结果的XML文档:
应用程序界面:
代码如下:
usingSystem;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Xml.Linq;
usingSystem.Web.Services;
usingSystem.Web.Services.Protocols;
usingSystem.Data.SqlClient;
publicpartialclass_Default:
System.Web.UI.Page
{
localhost.Servicecd=newlocalhost.Service();
protectedvoidPage_Load(objectsender,EventArgse)
//有个值会改变,改变之后要刷新当前页面的textbox里
if(!
Page.IsPostBack)
TextBox4.Text=DateTime.Now.Date.ToString("
yyyyMMdd_"
DataSource=.;
InitialCatalog=Patientimform;
IntegratedSecurity=True"
stringstr="
select医生编号,姓名fromdbo.doctor"
SqlCommandcom=newSqlCommand(str,conn);
//SqlDataReaderreader=com.ExecuteReader();
//inti=0;
//while(reader.Read())
//{
//comboBox1.Items.Add(reader.);
//i++;
//}
SqlDataAdapteradp=newSqlDataAdapter(str,conn);
DataTabledb=newDataTable();
adp.Fill(db);
DropDownList1.Items.Add("
未选择"
inti=0;
while(i<
db.Rows.Count)
DropDownList1.Items.Add(db.Rows[i][0].ToString().Trim()+"
"
+db.Rows[i][1].ToString().Trim());
i++;
//DropDownList1.SelectedIndex=1;
str="
select类别编号,类别名称fromdbo.category"
adp=newSqlDataAdapter(str,conn);
DataTableda1=newDataTable();
adp.Fill(da1);
DropDownList2.Items.Add("
i=0;
da1.Rows.Count)
DropDownList2.Items.Add(da1.Rows[i][0].ToString().Trim()+"
+da1.Rows[i][1].ToString().Trim());
//DropDownList2.SelectedIndex=1;
}
protectedvoidButton1_Click(objectsender,EventArgse)
inti1=Int32.Parse(TextBox1.Text.ToString());
inti2=Int32.Parse(TextBox2.Text.ToString());
intresult=cd.Subtr(i1,i2);
TextBox3.Text=result.ToString();
protectedvoidButton2_Click(objectsender,EventArgse)
intresult=cd.Subtra(i1,i2);
protectedvoidButton3_Click(objectsender,EventArgse)
intresult=cd.Subtrac(i1,i2);
protectedvoidButton4_Click(objectsender,EventArgse)
intresult=cd.Subtract(i1,i2);
protectedvoidButton5_Click(objectsender,EventArgse)
localhost1.Serviceds=newlocalhost1.Service();
stringname=TextBox6.Text.ToString();
DataTabletb=ds.Subtract(name);
guanchenggong.DataSource=tb;
guanchenggong.DataBind();
protectedvoidguanchenggong_SelectedIndexChanged(objectsender,EventArgse)
GridViewRowgridview=guanchenggong.Rows[guanchenggong.SelectedIndex];
TextBox4.Text=gridview.Cells[1].Text;
TextBox6.Text=gridview.Cells[2].Text;
TextBox5.Text=gridview.Cells[3].Text;
stringxingb=gridview.Cells[4].ToString().Trim();
if(xingb=="
男"
)
RadioButton1.Checked=true;
else
RadioButton2.Checked=true;
DropDownList1.SelectedIndex=int.Parse(gridview.Cells[5].Text);
DropDownList2.SelectedIndex=int.Parse(gridview.Cells[7].Text);
TextBox7.Text=gridview.Cells[6].Text;
protectedvoidButton7_Click(objectsender,EventArgse)
stringsex;
localhost1.Serviceda=newlocalhost1.Service();
stringid=TextBox4.Text.ToString();
stringsname=TextBox6.Text.ToString();
intage=int.Parse(TextBox5.Text);
if(RadioButton1.Checked)
sex=RadioButton1.Text.ToString();
sex=RadioButton2.Text.ToString();
stringdoctor=DropDownList1.SelectedIndex.ToString();
stringdct=numN(doctor);
stringtypea=DropDownList2.SelectedIndex.ToString();
stringty=numN(typea.ToString());
stringtype=TextBox7.Text.ToString();
Response.Write("
<
script>
alert('
+da.AD(id,sname,age,sex,dct,type,ty)+"
)<
/script>
publicstringnumN(stringstr)
stringnumber=null;
foreach(chariteminstr)
if(item>
=48&
&
item<
=58)
number+=item;
break;
returnnumber;
publicstringnowTime()
stringtime=DateTime.Now.Year.ToString();
if(DateTime.Now.Month<
10)
time=time+"
0"
+DateTime.Now.Month.ToString().Trim();
time=time+DateTime.Now.Month.ToString().Trim();
time=time+DateTime.Now.Day.ToString().Trim();
returntime;
protectedvoidguanchenggong_RowDeleting(objectsender,GridViewDeleteEventArgse)
localhost1.Servicecd1=newlocalhost1.Service();
stringname1=TextBox6.Text.ToString();
DataTabletb1=cd1.Subtract(name1);
stringstr=guanchenggong.SelectedIndex.ToString();
stringstr11=tb1.Rows[Int32.Parse(str)][0].ToString();
+cd1.de(str11)+"
protectedvoidButton6_Click(objectsender,EventArgse)
localhost1.Serviceup=newlocalhost1.Service();
stringid=TextBox4.Text.ToString();
+up.up(id,sname,age,sex,dct,type,ty)+"
(2)添加WEB服务引用:
运行:
点击查询
2、试验二:
编写一应用程序,实现对天气预报的Web服务的调用,要求界面能够按照地名查询当时的天气情况。
注:
天气预报Web服务接口为下网址:
添加引用:
using.webxml.www;
publicpart