1:建立的webservice工程正确运行。
a: 定义接口类
public interface ITestWebService {
public String GetTextInfo(String message);
}
b:实现类
public class TestWebServiceImpl implements ITestWebService {
public String GetTextInfo(String message) {
message = "Hello : " + message ;
System.out.println(message);
return message;
}
}
写个测试类,利用xfire相关函数测试当前webservice是否可以正确的调用
public static void main(String[] args) {
// TODO Auto-generated method stub
Service srvcModel = new ObjectServiceFactory().create(ITestWebService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String ServerURL ="http://192.168.100.1/TermSerivce/services/GetTextInfo";
try {
ITestWebService srvc = (ITestWebService)factory.create(srvcModel, ServerURL);
String result=srvc.GetTextInfo("ha ha!");
System.out.println(result);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
下面写js中调用
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<SCRIPT LANGUAGE="JavaScript">
<!--
var __XmlHttpPool__ =
{
m_MaxPoolLength : 10,
m_XmlHttpPool : [],
__requestObject : function()
{
var xmlhttp = null;
var pool = this.m_XmlHttpPool;
for ( var i=0 ; i < pool.length ; ++i )
{
if ( pool[i].readyState == 4 || pool[i].readyState == 0 ) { xmlhttp = pool[i]; break; }
}
if ( xmlhttp == null ) { return this.__extendPool(); }
return xmlhttp;
},
__extendPool : function()
{
if ( this.m_XmlHttpPool.length < this.m_MaxPoolLength )
{
var xmlhttp = null;
try
{
xmlhttp = new ActiveXObject('MSXML2.XMLHTTP');
}
catch(e)
{
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e2) {}
}
if ( xmlhttp ) { this.m_XmlHttpPool.push(xmlhttp); }
return xmlhttp;
}
},
RequestWebService: function(URL,method,value,callback)
{
this.__requestWebService(URL,method,value,callback);
},
__requestWebService: function(URL,method,value,callback)
{
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<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/">';
data = data + '<soap:Body>';
data = data + '<' + method + ' xmlns="http://tempuri.org/';
data = data + method + '">';
data = data + '<in0>'+value+'</in0>';
data = data + '</' + method + '>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>';
var xmlhttp = this.__requestObject();
if ( !xmlhttp ){ return null; }
xmlhttp.Open("POST",URL, true);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/example");
xmlhttp.onreadystatechange = function()
{
if ( xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete' ) { callback(xmlhttp.responseXML); }
};
xmlhttp.send(data);
},
PostData : function(URL,method, data, callback)
{
this.__receiveRemoteData(URL,'POST','type='+method+'&item='+data, callback);
},
__receiveRemoteData : function(url,httpmethod,data,callback)
{
var xmlhttp = this.__requestObject();
if ( !xmlhttp ){ return null; }
xmlhttp.open(httpmethod, URL, true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function()
{
if ( xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete' ) { callback(xmlhttp.responseText); }
};
xmlhttp.send(data);
},
CancelAll : function()
{
var extendPool = this.__extendPool;
this.__extendPool = function() { return null; }
for ( var i=0 ; i < this.m_XmlHttpPool.length ; ++i ) { this.m_XmlHttpPool[i].abort(); }
this.__extendPool = extendPool;
}
};
function recv(xml)
{
var ret=xml.getElementsByTagName_r("ns1:out")[0].firstChild.nodeValue;
alert(ret);
}
var URL="http://192.168.100.1/TermService/services/TermInfo";
__XmlHttpPool__.RequestWebService(URL,"GetTextInfo","ha ha",recv);
</Script>
</BODY>
</HTML>