WebService---web服务的使用
来源:互联网 发布:首席数据官联盟 编辑:程序博客网 时间:2024/05/18 07:39
一,什么是web服务
Web服务(Web Service)是基于XML和HTTPS的一种服务,其通信协议主要基于SOAP,服务的描述通过WSDL,通过UDDI来发现和获得服务的元数据。
可扩展的标记语言(XML)是Web service平台中表示数据的基本格式。除了易于建立和易于分析外,XML主要的优点在于它既是平台无关的,又是厂商无关的。 SOAP规范定义了SOAP消息的格式,以及怎样通过HTTP协议来使用SOAP。SOAP也是基于XML和XSD的,XML是SOAP的数据编码方式。Web service描述语言(WSDL)就是这样一个基于XML的语言,用于描述Web service及其函数、参数和返回值。
SOAP:最初是简单对象访问协议(Simple Object Access Protocol),SOAP 定义一个 XML 文档格式,该格式描述如何调用一段远程代码的方法
WSDL:Web 服务描述语言(Web Services Description Language)是一个描述 Web 服务的 XML 词汇表。
UDDI:统一描述、发现和集成(Universal Description, Discovery, and Integration)协议向 Web 服务注册中心定义 SOAP 接口。
使用web服务的好处:
1 跨防火墙的通信
2 应用程序集成
3 B2B的集成
4 软件和数据重用
web服务提供网址:www.webxml.com.cn
二,使用web服务
(1)web应用程序步骤:在web应用程序上右键---添加服务应用---高级---添加web引用---输入URL(下图)
(2)调用web服务代码:
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Items.Add("--请选择省--");
cn.com.webxml.webservice.WeatherWS ws = new WebServiceTest.cn.com.webxml.webservice.WeatherWS();
string[] strProvices = ws.getRegionProvince(); //获得所有的省份:每项中:湖北,31117
for (int i = 0; i <strProvices.Length; i++)
{
string[] strs = strProvices[i].Split(',');
string provinceName = strs[0];
DropDownList1.Items.Add(provinceName);
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > 0)
{
string strProviceName = DropDownList1.Text; //获得用户选中的省份
cn.com.webxml.webservice.WeatherWS ws = new WebServiceTest.cn.com.webxml.webservice.WeatherWS();
string[] strCitys = ws.getSupportCityString(strProviceName); //根据省份获得市
DropDownList2.Items.Add("--请选择市--");
for (int i = 0; i <strCitys.Length; i++)
{
string[] strs = strCitys[i].Split(',');
string cityName = strs[0];
DropDownList2.Items.Add(cityName);
}
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedIndex > 0)
{
string cityName = DropDownList2.Text;
cn.com.webxml.webservice.WeatherWS ws = new WebServiceTest.cn.com.webxml.webservice.WeatherWS();
string[] weathers= ws.getWeather(cityName, ""); //注意getWeather的参数
string str = "";
//调试找出自己要获得的数据
for (int i = 3; i < 10; i++)
{
str += weathers[i] + "<br>";
}
str += "<img src='" + weathers[10] + "'/><img src='" + weathers[11] + "'/>";
Label1.Text = str;
}
}
引用web服务如图所示:
根据调试获得自己需要的值:
三,自己写web服务
(1)步骤:在web引用程序上点击右键--添加新建项--web服务
(2)编写自己需要的方法,只需要把方法标记为[WebMethod]就可以了
(3)具体代码:
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
}
- WebService---web服务的使用
- webservice使用handler来增强web服务的功能
- 使用Web Services Explorer测试Webservice服务
- 使用 SOAP 协议调用 Web服务(WebService)
- WebService服务的简单使用
- WebService .net web服务
- Web服务 [WebService]
- webservice web服务
- Webservice学习笔记二,使用Axis发布简单的Web服务
- 使用jax-ws和spring创建和web容器共端口的webservice服务
- 在 PHP 中使用 SOAP 协议调用 Web服务(WebService)
- 使用Jersey开发RESTful的webservice服务
- Web项目调用webservice服务
- 如何使用WebService服务
- webservice-XFire开发一个简单的web服务
- 开发EJB容器模型的WEB服务(EJB WebService)
- Web服务和XFire实现Webservice的几种方式
- 搭建web项目结合spring+cxf的webservice服务
- ERP项目实施的15个规律摘抄笔记
- C# 字符串反转,数据排序
- java将日期修改修改为汉字
- PB窗口之间多参数的传递
- PC机的内存分配空间小记
- WebService---web服务的使用
- iPhone 利用CG API画一个饼图(Pie chart)
- n个人排成一圈,从1开始报数,数到3,退出,剩下的最后一个人
- 总结:导致项目失败的3个层次和14个原因
- MyEclipse 10优化技巧
- MySQL 数据库性能优化之SQL优化(这是 MySQL数据库性能优化专题 系列的第四篇文章)
- ubuntu 下安装jdk 以及ant命令
- 敏捷开发和CMMI的管理内容比较
- 深入理解iphone开发中的delegate by hennychen