在网上找了好久没一个写的详细的,我下载了一个axis1.4的 放在tomcat/webapps 目录下了 环境也设好了,应该没问题 做了一个HelloWard小测试
能过 http://localhost:8080/axis/Hello.jws?wsdl 地址可以正确访问了,可是我不明白我想调用一个远程的 .net写的 webservice 发送如下代码,我想不明白的是以下的这些代码怎么发?用什么函数?还是写在某个文件里?POST /searchservice.asmx HTTP/1.1
HOST: orion
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction:http://gse.giaval.com/LogonAsGuest<?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> <LogonAsGuest xmlns="http://gse.giaval.com/" /> </soap:Body>
</soap:Envelope>
call.setTargetEndpointAddress(new java.net.URL("http://orion/"));
call.setOperationName(new QName("http://orion/",method)); //这段蓝色的代码是什么意思为什么出现两个地址要怎么写// 下面这几行也不知道是什么意思 在网上找不到中文的文档 本来就对这方面薄弱 现在更是一头雾水 谁能解救我于苦海 在下感激不尽。
call.addParameter("input", org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN); //以下我都不知道是什么意思
call.setUseSOAPAction(true);
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_ARRAY);
call.setSOAPActionURI("http://tempuri.org/GetServerList");
Object[] k = (Object[])call.invoke(new Object[]{}); 网上找的资料 都是东一块西一块的
能过 http://localhost:8080/axis/Hello.jws?wsdl 地址可以正确访问了,可是我不明白我想调用一个远程的 .net写的 webservice 发送如下代码,我想不明白的是以下的这些代码怎么发?用什么函数?还是写在某个文件里?POST /searchservice.asmx HTTP/1.1
HOST: orion
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction:http://gse.giaval.com/LogonAsGuest<?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> <LogonAsGuest xmlns="http://gse.giaval.com/" /> </soap:Body>
</soap:Envelope>
call.setTargetEndpointAddress(new java.net.URL("http://orion/"));
call.setOperationName(new QName("http://orion/",method)); //这段蓝色的代码是什么意思为什么出现两个地址要怎么写// 下面这几行也不知道是什么意思 在网上找不到中文的文档 本来就对这方面薄弱 现在更是一头雾水 谁能解救我于苦海 在下感激不尽。
call.addParameter("input", org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN); //以下我都不知道是什么意思
call.setUseSOAPAction(true);
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_ARRAY);
call.setSOAPActionURI("http://tempuri.org/GetServerList");
Object[] k = (Object[])call.invoke(new Object[]{}); 网上找的资料 都是东一块西一块的
楼主【whttaotao】截止到2008-07-16 09:58:16的历史汇总数据(不包括此帖):
发帖的总数量:13 发帖的总分数:780 每贴平均分数:60
回帖的总数量:58 得分贴总数量:18 回帖的得分率:31%
结贴的总数量:12 结贴的总分数:680
无满意结贴数:3 无满意结贴分:105
未结的帖子数:1 未结的总分数:100
结贴的百分比:92.31 % 结分的百分比:87.18 %
无满意结贴率:25.00 % 无满意结分率:15.44 %
值得尊敬
http://www.cnblogs.com/tuyile006/archive/2008/03/14/1106294.html
jsp页面
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" language="javascript">
//设一个变量
var XMLHttpReq=false;
//创建一个XMLHttpRequest对象
function getXMLRequester( ){ var xmlhttp_request = false; try{ if( window.ActiveXObject ){ for( var i = 5; i; i-- ){ try{ if( i == 2 ){xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" ); }else{xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" ); xmlhttp_request.setRequestHeader("Content-Type","text/xml");xmlhttp_request.setRequestHeader("Content-Type","utf-8"); }break;} catch(e){ xmlhttp_request = false; } } }else if( window.XMLHttpRequest ){ xmlhttp_request = new XMLHttpRequest(); if (xmlhttp_request.overrideMimeType) { xmlhttp_request.overrideMimeType('text/xml'); } } }catch(e){ xmlhttp_request = false; } return xmlhttp_request ;}
//发送请求函数
function send(url){
XMLHttpReq=getXMLRequester();
XMLHttpReq.open("GET",url,true);
XMLHttpReq.onreadystatechange=proce; //指定响应的函数
XMLHttpReq.send(null); //发送请求
}
function proce(){
if(XMLHttpReq.readyState==4){ //对象状态
if(XMLHttpReq.status==200){//信息已成功返回,开始处理信息
var res=XMLHttpReq.responseXML.getElementsByTagName("content")[0].firstChild.data;
window.alert(res);
}else{
window.alert("所请求的页面有异常");
}
}
}
//身份验证
function check(){
var name=document.getElementById("name").value;
if(name==""){
alert("请输入姓名");
return false;
}
else{
send('servlet/Check?name='+name);
}
}
</script>
</head> <body>
<form action="servlet/Check" method="post">
<table>
<tr>
<td>
姓名:
<input id="name" type="text" name="name" />
<p>
<input type="button" value="检测!" onClick="check()" />
</td>
</tr>
</table>
</form>
</body>
</html>
servlet页面
package com.oy.TestAjax;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class Check extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 4365604152068351525L;
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
//设置接收的信息的字符集
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("name");
//设置输出的信息的格式及字符集
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
//创建输出流
PrintWriter out=response.getWriter();
out.println("<pront>");
if(name.equals("bruce")){
out.println("<content>"+"对不起,此网名已注册!"+"</content>");
}else{
out.println("<content>"+"此网名可以注册!"+"</content>");
}
out.println("</pront>");
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException { doGet(request,response);
}
public void init() throws ServletException {
}}
但这个消息一般不需要手工生成,开发包会帮助自动生成这个消息,减轻编程负担。下面蓝色和黑色代码就是生成类似于红色部分的内容。所以红色部分是不需要你明确写函数来发送的。web服务有调用地址(类似于网页地址)、要调用的方法及方法参数,蓝色和黑色部分就是来设置这些,下面给你说明:call.setTargetEndpointAddress(new java.net.URL("http://orion/"));
//上句设置Web服务的调用地址
call.setOperationName(new QName("http://orion/",method));
//上句设置要调用的函数名,http://orion/为函数名的命名空间,method是函数名,两者合在一起时函数的全名
call.addParameter("input", org.apache.axis.encoding.XMLType.XSD_STRING,ParameterMode.IN);
//上句设置调用参数,字符串格式,输入参数
call.setUseSOAPAction(true);
//设置是否包含SoapAction,对应于红色代码中的SOAPAction:http://gse.giaval.com/LogonAsGuest
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_ARRAY);
//设置函数返回类型,数组类型
call.setSOAPActionURI("http://tempuri.org/GetServerList");
//设置soapAction内容,对应于红色代码中的SOAPAction:http://gse.giaval.com/LogonAsGuest
Object[] k = (Object[])call.invoke(new Object[]{});
//执行函数调用