叶明的javablog

java学习天堂,个人关于其他blog:blog.javaworker.cn,欢迎大家访问
posts - 64, comments - 50, trackbacks - 0, articles - 3

新建工程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

Feedback

# re: (转帖)利用xfire开发webservice专题[四]  回复  更多评论   

2008-04-03 16:40 by fdg
贴出来丢人!

# re: (转帖)利用xfire开发webservice专题[四]  回复  更多评论   

2009-01-06 20:40 by junior_java_er
对于新手来说挺好的啊,为什么说丢人呢.

只有注册用户登录后才能发表评论。


网站导航: