初学WebService
来源:互联网 发布:ubuntu配置网关 编辑:程序博客网 时间:2024/06/04 23:24
1、新建一个web项目
2、在项目名称单击右键->添加->服务引用,弹出窗口后点击“高级”,再点击“添加Web服务”
3、在URL填入要引用的web服务的路径,例如(天气预报:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx),再点击傍边的“转到”按钮
4、修改好Web引用名后(例如:HttpWeatherWebService),点击”添加引用“,在项目下的文件Web References中就有刚添加的引用了
5、天气预报例子的代码
WebForm1.aspx文件的代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="GetWebService.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
中文城市名称:<asp:TextBox ID="txtCityName" runat="server"></asp:TextBox>
<asp:Button ID="Submit" runat="server" Text="提交" OnClick="Submit_Click" Height="21px" /><br />
城市天气预报信息<br />
<asp:ListBox ID="ListBox1" runat="server" Height="300px" Width="100%"></asp:ListBox>
</div>
</form>
</body>
</html>
WebForm1.aspx.cs文件的按钮事件代码:
protected void Submit_Click(object sender, EventArgs e)
{
HttpWeatherWebService.WeatherWebService ws = new HttpWeatherWebService.WeatherWebService();
string[] r = ws.getWeatherbyCityName(this.txtCityName.Text);
this.lboxWeatherMsg.Items.Clear();
if (r == null)
{
this.lboxWeatherMsg.Text = "无" + this.txtCityName.Text + "城市的天气信息";
return;
}
foreach (string i in r)
{
this.lboxWeatherMsg.Items.Add(i);
}
}
运行结果
- WebService初学
- WebService初学
- 初学WebService
- 初学WebService
- 初学WebService,jax-ws实现webService
- 初学webservice,使用axis2第一个例子
- webservice学习之AXIS初学笔记--创建自己的webservice
- webservice学习之AXIS初学笔记--环境配置
- WebService之Axis2初学入门工程(详细)
- 初学webservice抛异常Unable to establish loopback connection
- 初学...
- 初学
- 初学
- 初学
- 初学
- 初学
- 初学
- 初学
- 谨记手机端页面要使用em,而不是用px,以及MAX,MIN-width
- 解决vs2013启动出现“cannot find one or more components .Please reinstall the application”
- Quartz实现任务调度
- spring mvc的工作流程
- 只有五行的Floyd最短路径算法
- 初学WebService
- linux 打开文件数 too many open files 解决方法
- 算法训练 4-1打印下述图形
- 【实践】基于spark的CF实现及优化
- Android——从零开始写一款开源项目
- iOS 服务器返回NSData数据,解析为null
- 远程oracle热备
- (读书笔记)《玩着玩着就能成为PPT高手》——说的漂亮
- Centos 6.9 Redis 4.0.1 主从配置