新建工程useWebService,并且建立client和services包
bulid path中导入,XFire 1.1 core libraries 和XFire 1.1 HTTP client libraries.
SayHello.java
----------------------------------------
package client;
import java.net.MalformedURLException;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import services.IHelloWorldTest;
public class SayHello {
public String say(String name)
{
String result="";
Service srvcModel = new ObjectServiceFactory().create(IHelloWorldTest.class);
XFireProxyFactory factory =
new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String helloWorldURL = "http://localhost:8080/HelloWorld/services/HelloWorldTest";
try {
IHelloWorldTest srvc = (IHelloWorldTest)factory.create(srvcModel, helloWorldURL);
result = srvc.sayHello(name);
} catch (MalformedURLException e) {
e.printStackTrace();
}finally{
return result;}
}
}
--------------------------------------------------------------
IHelloWorldTest .java
---------------------------------------------------------------
package services;
public interface IHelloWorldTest {
public String sayHello(String message);
}
-----------------------------------------------------------------
创建index.jsp,body部分
-----------------------
<form name="form1" action="say.jsp" method="POST">
您的大名:<input name="userName" type="text"/> <input value="提交" type="submit"/>
</form>
-------------------------------
创建say.jsp,body部分
----------------------------------------------------------------
<%String name=(String)request.getParameter("userName");
String result=new SayHello().say(name);
%>
webService远程调用结果: <%=result %>
------------------------------------------------------------------------
运行下测试!OK