我是一个菜鸟,开发经验才1年多,跪求知道下!!给个简单易懂的网站也行
我想知道webservices到底是个什么东西。
还有就是网上说的webservices地址,难道就是调用一个地址那么简单?
我这里有一个以前朋友给的webservices的项目是查询城市的。package com.huawei.util;import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;public class WeatherReport {
/**
 * 获取SOAP的请求头,并替换其中的标志符号为用户输入的城市
 * 
 * 编写者:
 * 简单对象协议
 * @param city
 *            用户输入的城市名称
 * @return 客户将要发送给服务器的SOAP请求
 */
private static String getSoapRequest(String city) {
StringBuilder sb = new StringBuilder();
sb
.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>    <getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">"
+ "<theCityName>" + city
+ "</theCityName>    </getWeatherbyCityName>"
+ "</soap:Body></soap:Envelope>");
return sb.toString();
} /**
 * 用户把SOAP请求发送给服务器端,并返回服务器点返回的输入流
 * 
 * 编写者:
 * 
 * @param city
 *            用户输入的城市名称
 * @return 服务器端返回的输入流,供客户端读取
 * @throws Exception
 */
private static InputStream getSoapInputStream(String city) throws Exception {
try {
String soap = getSoapRequest(city);
if (soap == null) {
return null;
}
URL url = new URL(
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true); conn.setRequestProperty("Content-Length", Integer.toString(soap
.length()));
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestProperty("SOAPAction",
"http://WebXml.com.cn/getWeatherbyCityName"); OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");
osw.write(soap);
osw.flush();
osw.close(); InputStream is = conn.getInputStream();
return is;
} catch (Exception e) {
e.printStackTrace();
return null;
}
} /**
 * 对服务器端返回的XML进行解析
 * 
 * 编写者:
 * 
 * @param city
 *            用户输入的城市名称
 * @return 字符串 用,分割
 */
public static String getWeather(String city) {
try {
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = getSoapInputStream(city);
doc = db.parse(is);
NodeList nl = doc.getElementsByTagName("string");
StringBuffer sb = new StringBuffer(); for (int count = 0; count < nl.getLength(); count++) {
Node n = nl.item(count);
if(n.getFirstChild().getNodeValue().equals("查询结果为空!")) {
sb = new StringBuffer("#") ;
break ;
}
sb.append(n.getFirstChild().getNodeValue() + "#\n");
}
is.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/**
 * 测试用
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
System.out.println(getWeather("北京"));
}
}
SOAP

解决方案 »

  1.   

    两个系统间通过xml传递信息,一个发送xml请求,一个返回xml相应,各自解析。发的发参数信息,收的进行服务运算返回结果。
      

  2.   

    两个系统间通过xml传递信息,一个发送xml请求,一个返回xml相应,各自解析。发的发参数信息,收的进行服务运算返回结果。
      

  3.   

    举个例子楼主应该会明白些,比如我们想开发个应用,其中需要实现地图的功能,但是我们总不能自己写个地图应用吧,这是你发现百度跟谷歌有这样的功能,并且他们对开发这提供了接口,允许我们通过这些接口来访问他们的地图功能,其中这些接口就可以理解为WebService,类似的有天气预报的接口,qq的,微博的,人人的等等...
      

  4.   

    以http方式提供的服务比如:天气预报、股票信息等等。你只需要调用他提供的webservices就可以完成这些功能。
      

  5.   

    webservice核心还是有点像servlet的,这里有个博文,LZ可以对着博文,看看源码(可以通过反编译工具查看相应的jar包):
    http://blog.csdn.net/oolala/article/details/3960756