`
tomgooityeeee
  • 浏览: 73464 次
文章分类
社区版块
存档分类
最新评论

Web Service实践之——开始XFire

阅读更多

    一、Axis与XFire的比较<br>XFire是与Axis2 并列的新一代WebService平台。之所以并称为新一代,因为它:<br>1、支持一系列Web Service的新标准--JSR181、WSDL2.0 、JAXB2、WS-Security等;<br>2、使用Stax解释XML,性能有了质的提高。XFire采用Woodstox 作Stax实现;<br>3、容易上手,可以方便快速地从pojo发布服务; <br>4、Spring的结合;<br>5、灵活的Binding机制,包括默认的Acegis,xmlbeans,jaxb2,castor。<br>?<br>XFire与Axis1性能的比较<br>1、XFire比Axis1.3快2-6倍<br>2、XFire的响应时间是Axis1.3的1/2到1/5<br>?<br>XFire与Axis2的比较<br>虽然XFire与Axis2都是新一代的WebService平台,但是Axis2的开发者太急于推出1.0版本,所以1.0还不是一个稳定的版本,它的开发者宣称1.1版本即将推出,希望1.1版本会是个稳定的版本。在XFire捐献给apache后有人认为Axis2将会灭亡。其实在很多人眼里,Axis2并不是pojo形式,现在也好象XFire比Axis更有市场,也有很多人开始从Axis转向XFire。<br>据说,XFire确实比Axis2简单很多

AXIS VS CXF<br>在SOA领域,我们认为Web Service是SOA体系的构建单元(building block)。对于作过WebService的开发人员来说,AXIS和CXF一定都不会陌生。这两个产品都是Apache孵化器下面的Web Service开源开发工具。 Axis2的最新版本是1.3,CXF现在已经到了2.0版本。

这两个框架 都是从已有的开源项目发展起来的。Axis2是从Axis1.x系列发展而来。CXF则是XFire和Celtix项目的结合产品。Axis2是从底层全部重新实现,使用了新的扩展性更好模块架构。 CXF也重新的深化了XFire和Celtix这两个开发工具。

新产品的退出导致了几个问题。是不是现有的使用Axis 1.x,XFire和Celix的应用需要迁移的新的版本上。如果一个开发人员确定要迁移它的应用到新的框架上,那么他应该选择哪一个呢?相反的,如果一个开发者决定从头开发一个新的Web Service,他应该使用哪个呢? 这两个框架哪一个更好一些呢?

对于系统迁移来说,也许迁移到新的框架并不难。Axis和CXF都提供了迁移的指导。能够给开发者一些迁移的技巧和经验。但是对于这样迁移,这两个开源项目都没有提供迁移的工具。对于这样的迁移工作,尽管很值得去寻找所有的可行方案。Axis2和CXF都有各自不同的WebService开发方法,每个方法都有相当数量拥护者。

通过一个比较矩阵来比较Axis2和CXF变得有现实的意义。这两个项目都开发不够成熟,但是最主要的区别在以下几个方面:<br>1. CXF支持 WS-Addressing,WS-Policy, WS-RM, WS-Security和WS-I Basic Profile。Axis2不支持WS-Policy,但是承诺在下面的版本支持。<br>2. CXF可以很好支持Spring。Axis2不能<br>3. AXIS2支持更广泛的数据并对,如XMLBeans,JiBX,JaxMe和JaxBRI和它自定义的数据绑定ADB。注意JaxME和JaxBRI都还是试验性的。CXF只支持JAXB和Aegis。在CXF2.1<br>4. Axis2支持多语言-除了Java,他还支持C/C++版本。

比较这两个框架的Web Service开发方法与比较它们的特性同样重要。 从开发者的角度,两个框架的特性相当的不同。 Axis2的开发方式类似一个小型的应用服务器,Axis2的开发包要以WAR的形式部署到Servlet容器中,比如Tomcat,通过这些容器可以对工作中的Web Service进行很好的监控和管理。Axis2 的Web administrion模块可以让我们动态的配置Axis2.一个新的服务可以上载,激活,使之失效,修改web服务的参数。管理UI也可以管理一个或者多个处于运行状态的服务。这种界面化管理方式的一个弊端是所有在运行时修改的参数没有办法保存,因为在重启动之后,你所做的修改就会全部失效。

Axis2允许自己作为独立的应用来发布Web Service,并提供了大量的功能和一个很好的模型,这个模型可以通过它本身的架构(modular architecture)不断添加新的功能。有些开发人员认为这种方式对于他们的需求太过于繁琐。这些开发人员会更喜欢CXF。

CXF更注重开发人员的工效(ergonomics)和嵌入能力(embeddability)。大多数配置都可以API来完成,替代了比较繁琐的XML配置文件, Spring的集成性经常的被提及,CXF支持Spring2.0和CXF's API和Spring的配置文件可以非常好的对应。CXF强调代码优先的设计方式(code-first design),使用了简单的API使得从现有的应用开发服务变得方便。

不过你选择Axis2还是CXF,你都可以从开源社区得到大量的帮助。这两个框架都有商业公司提供服务,WSO2提供AXIS2的支持,Iona提供CXF的支持。这两公司都有很活跃的开发者社区。 Axis2出现的时间较早,CXF的追赶速度快。我的建议是:如果你需要多语言的支持,你应该选择AXIS2。如果你需要把你的实现侧重JAVA并希望和Spring集成,CXF就是更好的选择,特别是把你的Web Service嵌入其他的程序中。如果你觉得这两个框架的新特性对于你并没有太大的用处,你会觉得Axis1也是不错的选择,你应该继续使用它知道你有充分的理由去更换它。

<br>二、开始XFire的生火之旅:<br>1、配置XFire运行环境:<br>在Tomcat下新建一个Web Applications,命名为stove,然后在其WEB-INF目录下新建一个web.xml文件,文件中输入:

<div class="dp-highlighter">
<div class="bar">
<div class="tools">Xml代码 <a title="复制代码" href="http://lishuaishuai.iteye.com/admin/blogs/#"><img src="http://lishuaishuai.iteye.com/images/icon_copy.gif" alt="复制代码"></a>?<a title="收藏这段代码"><img class="star" src="http://lishuaishuai.iteye.com/images/icon_star.png" alt="收藏代码"><img class="spinner" style="display: none;" src="http://lishuaishuai.iteye.com/images/spinner.gif" alt=""></a>


<ol class="dp-xml">
  • <span><span style="color: #006699;"><span class="tag"><?</span><span class="tag-name">xml</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">version</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"1.0"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">encoding</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"GB2312"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span></span>
  • <span><!DOCTYPE?web-app ??</span>
  • <span>????PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN" ??</span>

  • <li>
    <span>????"http://java.sun.com/dtd/web-app_2_3.dtd"</span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
  • <span>???? ??</span>

  • <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">web-app</span><span class="tag">></span></span><span>??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet-name</span><span class="tag">></span></span><span>XFireServlet</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet-name</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">display-name</span><span class="tag">></span></span><span>XFire?Servlet</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">display-name</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet-class</span><span class="tag">></span></span><span>org.codehaus.xfire.transport.http.XFireConfigurableServlet</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet-class</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet</span><span class="tag">></span></span><span>??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet-mapping</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet-name</span><span class="tag">></span></span><span>XFireServlet</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet-name</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">url-pattern</span><span class="tag">></span></span><span>/servlet/XFireServlet/*</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">url-pattern</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet-mapping</span><span class="tag">></span></span><span>??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet-mapping</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">servlet-name</span><span class="tag">></span></span><span>XFireServlet</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet-name</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">url-pattern</span><span class="tag">></span></span><span>/services/*</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">url-pattern</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">servlet-mapping</span><span class="tag">></span></span><span>??</span>
    </li>
  • <span>??</span>

  • <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">web-app</span><span class="tag">></span></span><span>??</span>
    </li>
    </ol>

    <?xml version="1.0" encoding="GB2312">
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
        
    <web-app>
    
      <servlet>
        <servlet-name>XFireServlet</servlet-name>
        <display-name>XFire Servlet</display-name>
        <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>XFireServlet</servlet-name>
        <url-pattern>/servlet/XFireServlet/*</url-pattern>
      </servlet-mapping>
    
      <servlet-mapping>
        <servlet-name>XFireServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
      </servlet-mapping>
    
    </web-app>
    
    

    其中主要就是引入了XFireServlet,用以处理Web Service请求,并且负责提供Web Service的WSDL,如果你发布了一个名为BookService的WebService,则可以通过网址:<br>http://<服务器>[:端口]/<webapp名>/services/BookService<br>来访问这个WebService,并且通过地址:<br>http://<服务器>[:端口]/<webapp名>/services/BookService?WSDL? 来得到这个WebService的WSDL信息。

    2、开发最简单的WebService<br>在WEB-INF目录下新建src文件夹,然后再建一个package:<br>cn.com.pansky.webservice.xfire.study<br>,在这个包下面新建一个接口:

    <div class="dp-highlighter">
    <div class="bar">
    <div class="tools">Java代码 <a title="复制代码" href="http://lishuaishuai.iteye.com/admin/blogs/#"><img src="http://lishuaishuai.iteye.com/images/icon_copy.gif" alt="复制代码"></a>?<a title="收藏这段代码"><img class="star" src="http://lishuaishuai.iteye.com/images/icon_star.png" alt="收藏代码"><img class="spinner" style="display: none;" src="http://lishuaishuai.iteye.com/images/spinner.gif" alt=""></a>


    <ol class="dp-j">
  • <span><span class="keyword"><span style="color: #7f0055;">package</span></span><span>?cn.com.pansky.webservice.xfire.study; ??</span></span>
  • <span>??</span>

  • <li>
    <span class="keyword"><span style="color: #7f0055;">public</span></span><span>?</span><span class="keyword"><span style="color: #7f0055;">interface</span></span><span>?SayHiService{ ??</span>
    </li>
    <li>
    <span>??</span><span class="keyword"><span style="color: #7f0055;">public</span></span><span>?String?sayHi(String?name); ??</span>
    </li>
  • <span>}??</span>

  • </ol>

    package cn.com.pansky.webservice.xfire.study;
    
    public interface SayHiService{
      public String sayHi(String name);
    }
    
    

    这个接口是告诉服务器你的WebService哪些方法可以被用户调用的。下面我们再来写一个SayHiService的实现类,以完成业务逻辑:

    <div class="dp-highlighter">
    <div class="bar">
    <div class="tools">Java代码 <a title="复制代码" href="http://lishuaishuai.iteye.com/admin/blogs/#"><img src="http://lishuaishuai.iteye.com/images/icon_copy.gif" alt="复制代码"></a>?<a title="收藏这段代码"><img class="star" src="http://lishuaishuai.iteye.com/images/icon_star.png" alt="收藏代码"><img class="spinner" style="display: none;" src="http://lishuaishuai.iteye.com/images/spinner.gif" alt=""></a>


    <ol class="dp-j">
  • <span><span class="keyword"><span style="color: #7f0055;">package</span></span><span>?cn.com.pansky.webservice.xfire.study; ??</span></span>
  • <span>??</span>

  • <li>
    <span class="keyword"><span style="color: #7f0055;">public</span></span><span>?</span><span class="keyword"><span style="color: #7f0055;">class</span></span><span>?SayHiServiceImpl?</span><span class="keyword"><span style="color: #7f0055;">implements</span></span><span>?SayHiService{ ??</span>
    </li>
    <li>
    <span>??</span><span class="keyword"><span style="color: #7f0055;">public</span></span><span>?String?sayHi(String?name){ ??</span>
    </li>
    <li>
    <span>????</span><span class="keyword"><span style="color: #7f0055;">if</span></span><span>(name==</span><span class="keyword"><span style="color: #7f0055;">null</span></span><span>){ ??</span>
    </li>
    <li>
    <span>??????</span><span class="keyword"><span style="color: #7f0055;">return</span></span><span>?</span><span class="string"><span style="color: #0000ff;">"连名字也不肯告诉我吗?"</span></span><span>; ??</span>
    </li>
  • <span>????} ??</span>

  • <li>
    <span>????</span><span class="keyword"><span style="color: #7f0055;">return</span></span><span>?name+</span><span class="string"><span style="color: #0000ff;">",?你吃了吗?没吃回家吃去吧。"</span></span><span>; ??</span>
    </li>
  • <span>??} ??</span>
  • <span>??</span>

  • <li>
    <span>??</span><span class="keyword"><span style="color: #7f0055;">public</span></span><span>?String?不告诉你(){ ??</span>
    </li>
    <li>
    <span>????</span><span class="keyword"><span style="color: #7f0055;">return</span></span><span>?</span><span class="string"><span style="color: #0000ff;">"我的名字不告诉你!"</span></span><span>; ??</span>
    </li>
  • <span>??} ??</span>
  • <span>}??</span>

  • </ol>

    package cn.com.pansky.webservice.xfire.study;
    
    public class SayHiServiceImpl implements SayHiService{
      public String sayHi(String name){
        if(name==null){
          return "连名字也不肯告诉我吗?";
        }
        return name+", 你吃了吗?没吃回家吃去吧。";
      }
    
      public String 不告诉你(){
        return "我的名字不告诉你!";
      }
    }
    
    

    ?这个类实现了sayHi方法,该方法是可以通过WebService调用访问到的。另外还实现了一个方法“不告诉你”,该方法因为没有在接口SayHiService中定义,所以不能被WebService调用到。<br>?? 这个例子足够简单吧,就跟我们刚学Java时写的"Hello world"没什么两样。<br>到这里为止,我们做的跟平时的Java开发没啥区别,该如何来发布WebService呢?

    3、把JAVA类发布为WebService:<br>在WEB-INF/classes目录下新建文件夹:META-INF/xfire,然后在该文件夹下新建一个XML文件:services.xml,文件内容如下:

    <div class="dp-highlighter">
    <div class="bar">
    <div class="tools">Xml代码 <a title="复制代码" href="http://lishuaishuai.iteye.com/admin/blogs/#"><img src="http://lishuaishuai.iteye.com/images/icon_copy.gif" alt="复制代码"></a>?<a title="收藏这段代码"><img class="star" src="http://lishuaishuai.iteye.com/images/icon_star.png" alt="收藏代码"><img class="spinner" style="display: none;" src="http://lishuaishuai.iteye.com/images/spinner.gif" alt=""></a>


    <ol class="dp-xml">
  • <span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">beans</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://xfire.codehaus.org/config/1.0"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span></span>

  • <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">service</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span></span><span>SayHiService</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">namespace</span><span class="tag">></span></span><span>http://cn.com.pansky/SayHiService</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">namespace</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">serviceClass</span><span class="tag">></span></span><span>cn.com.pansky.webservice.xfire.study.SayHiService</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">serviceClass</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">implementationClass</span><span class="tag">></span></span><span>cn.com.pansky.webservice.xfire.study.SayHiServiceImpl</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">implementationClass</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">service</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">beans</span><span class="tag">></span></span><span>??</span>
    </li>
    </ol>

    <beans xmlns="http://xfire.codehaus.org/config/1.0">
      <service>
        <name>SayHiService</name>
        <namespace>http://cn.com.pansky/SayHiService</namespace>
        <serviceClass>cn.com.pansky.webservice.xfire.study.SayHiService</serviceClass>
        <implementationClass>cn.com.pansky.webservice.xfire.study.SayHiServiceImpl</implementationClass>
      </service>
    </beans>
    

    ?这个文件定义一个WebService: SayHiService,并同时定义了接口和实现类。<br>好了,该建的文件基本建完了,现在想办法把src下的java文件编译成class,并复制到WEB-INF/classes目录下

    4、启动Tomcat,测试WebService<br>如果Tomcat还没配置好,抽两分钟再配一下。再把Tomcat启动起来。<br>再打开浏览器,输入:<br><span style="color: #006699;">http://localhost/stove/services</span><br>,服务器返回的结果如下:<br>Available Services:<br>??? * SayHiService [wsdl]<br>???? Generated by XFire ( <span style="color: #006699;">http://xfire.codehaus.org</span> ) <br>我们看到我们的WebService已经布署成功了,我们再看看它的WSDL信息:

    <div class="dp-highlighter">
    <div class="bar">
    <div class="tools">Xml代码 <a title="复制代码" href="http://lishuaishuai.iteye.com/admin/blogs/#"><img src="http://lishuaishuai.iteye.com/images/icon_copy.gif" alt="复制代码"></a>?<a title="收藏这段代码"><img class="star" src="http://lishuaishuai.iteye.com/images/icon_star.png" alt="收藏代码"><img class="spinner" style="display: none;" src="http://lishuaishuai.iteye.com/images/spinner.gif" alt=""></a>


    <ol class="dp-xml">
  • <span><span style="color: #006699;"><span class="tag"><?</span><span class="tag-name">xml</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">version</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"1.0"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">encoding</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"UTF-8"</span></span><span class="tag"><span style="color: #006699;">?></span></span><span>??</span></span>

  • <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:definitions</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">targetNamespace</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://cn.com.pansky/SayHiService"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:tns</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://cn.com.pansky/SayHiService"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:wsdlsoap</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://schemas.xmlsoap.org/wsdl/soap/"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:soap12</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://www.w3.org/2003/05/soap-envelope"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:xsd</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://www.w3.org/2001/XMLSchema"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:soapenc11</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://schemas.xmlsoap.org/soap/encoding/"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:soapenc12</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://www.w3.org/2003/05/soap-encoding"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:soap11</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://schemas.xmlsoap.org/soap/envelope/"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:wsdl</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://schemas.xmlsoap.org/wsdl/"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:types</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:schema</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">xmlns:xsd</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://www.w3.org/2001/XMLSchema"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">attributeFormDefault</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"qualified"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">elementFormDefault</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"qualified"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">targetNamespace</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://cn.com.pansky/SayHiService"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:element</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHi"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:complexType</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:sequence</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:element</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">maxOccurs</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"1"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">minOccurs</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"1"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"in0"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">nillable</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"true"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">type</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"xsd:string"</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:sequence</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:complexType</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:element</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:element</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiResponse"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:complexType</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:sequence</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"><</span><span class="tag-name">xsd:element</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">maxOccurs</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"1"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">minOccurs</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"1"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"out"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">nillable</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"true"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">type</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"xsd:string"</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:sequence</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:complexType</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:element</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">xsd:schema</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:types</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:message</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiRequest"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:part</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"parameters"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">element</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"tns:sayHi"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:part</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:message</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:message</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiResponse"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:part</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"parameters"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">element</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"tns:sayHiResponse"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:part</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:message</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:portType</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"SayHiServicePortType"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:operation</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHi"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:input</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiRequest"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">message</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"tns:sayHiRequest"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:input</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:output</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiResponse"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">message</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"tns:sayHiResponse"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:output</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:operation</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:portType</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:binding</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"SayHiServiceHttpBinding"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">type</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"tns:SayHiServicePortType"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdlsoap:binding</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">style</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"document"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">transport</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://schemas.xmlsoap.org/soap/http"</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:operation</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHi"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdlsoap:operation</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">soapAction</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">""</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:input</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiRequest"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdlsoap:body</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">use</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"literal"</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:input</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:output</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"sayHiResponse"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdlsoap:body</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">use</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"literal"</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:output</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:operation</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:binding</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:service</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"SayHiService"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdl:port</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">name</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"SayHiServiceHttpPort"</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">binding</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"tns:SayHiServiceHttpBinding"</span></span><span class="tag"><span style="color: #006699;">></span></span><span>??</span>
    </li>
    <li>
    <span>??????</span><span style="color: #006699;"><span class="tag"><</span><span class="tag-name">wsdlsoap:address</span></span><span>?</span><span class="attribute"><span style="color: #ff0000;">location</span></span><span>=</span><span class="attribute-value"><span style="color: #0000ff;">"http://localhost/stove/services/SayHiService"</span></span><span class="tag"><span style="color: #006699;">/></span></span><span>??</span>
    </li>
    <li>
    <span>????</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:port</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span>??</span><span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:service</span><span class="tag">></span></span><span>??</span>
    </li>
    <li>
    <span style="color: #006699;"><span class="tag"></</span><span class="tag-name">wsdl:definitions</span><span class="tag">></span></span><span>??</span>
    </li>
    </ol>

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions targetNamespace="http://cn.com.pansky/SayHiService" xmlns:tns="http://cn.com.pansky/SayHiService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
      <wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://cn.com.pansky/SayHiService">
    <xsd:element name="sayHi">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="sayHiResponse">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
      </wsdl:types>
      <wsdl:message name="sayHiRequest">
        <wsdl:part name="parameters" element="tns:sayHi">
        </wsdl:part>
      </wsdl:message>
      <wsdl:message name="sayHiResponse">
        <wsdl:part name="parameters" element="tns:sayHiResponse">
        </wsdl:part>
      </wsdl:message>
      <wsdl:portType name="SayHiServicePortType">
        <wsdl:operation name="sayHi">
          <wsdl:input name="sayHiRequest" message="tns:sayHiRequest">
        </wsdl:input>
          <wsdl:output name="sayHiResponse" message="tns:sayHiResponse">
        </wsdl:output>
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="SayHiServiceHttpBinding" type="tns:SayHiServicePortType">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="sayHi">
          <wsdlsoap:operation soapAction=""/>
          <wsdl:input name="sayHiRequest">
            <wsdlsoap:body use="literal"/>
          </wsdl:input>
          <wsdl:output name="sayHiResponse">
            <wsdlsoap:body use="literal"/>
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="SayHiService">
        <wsdl:port name="SayHiServiceHttpPort" binding="tns:SayHiServiceHttpBinding">
          <wsdlsoap:address location="http://localhost/stove/services/SayHiService"/>
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>
    

    ?这个文件跟我们用Axis生成的基本是一样的。

    5、享受美味的时刻<br>WebService这道大餐算是烹制好了,现在是享用美餐的时候了。<br>我们写一个客户端吃掉这道大餐:

    <div class="dp-highlighter">
    <div class="bar">
    <div class="tools">Java代码 <a title="复制代码" href="http://lishuaishuai.iteye.com/admin/blogs/#"><img src="http://lishuaishuai.iteye.com/images/icon_copy.gif" alt="复制代码"></a>?<a title="收藏这段代码"><img class="star" src="http://lishuaishuai.iteye.com/images/icon_star.png" alt="收藏代码"><img class="spinner" style="display: none;" src="http://lishuaishuai.iteye.com/images/spinner.gif" alt=""></a>


    <ol class="dp-j">
  • <span><span class="keyword"><span style="color: #7f0055;">package</span></span><span>?cn.com.pansky.webservice.xfire.study; ??</span></span>
  • <span>??</span>

  • <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?java.net.MalformedURLException; ??</span>
    </li>
    <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?java.util.Map; ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?org.codehaus.xfire.client.Client; ??</span>
    </li>
    <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?org.codehaus.xfire.client.XFireProxyFactory; ??</span>
    </li>
    <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?org.codehaus.xfire.service.Service; ??</span>
    </li>
    <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?org.codehaus.xfire.service.binding.ObjectServiceFactory; ??</span>
    </li>
    <li>
    <span class="keyword"><span style="color: #7f0055;">import</span></span><span>?org.codehaus.xfire.transport.http.CommonsHttpMessageSender; ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span class="keyword"><span style="color: #7f0055;">public</span></span><span>?</span><span class="keyword"><span style="color: #7f0055;">class</span></span><span>?SayHiClient{ ??</span>
    </li>
    <li>
    <span>??</span><span class="keyword"><span style="color: #7f0055;">public</span></span><span>?</span><span class="keyword"><span style="color: #7f0055;">static</span></span><span>?</span><span class="keyword"><span style="color: #7f0055;">void</span></span><span>?main(String?args[])?{ ??</span>
    </li>
    <li>
    <span>????String?serviceURL?=?</span><span class="string"><span style="color: #0000ff;">"http://localhost/stove/services/SayHiService"</span></span><span>; ??</span>
    </li>
    <li>
    <span>????Service?serviceModel?=?</span><span class="keyword"><span style="color: #7f0055;">new</span></span><span>?ObjectServiceFactory().create(SayHiService.</span><span class="keyword"><span style="color: #7f0055;">class</span></span><span>,</span><span class="keyword"><span style="color: #7f0055;">null</span></span><span>,</span><span class="string"><span style="color: #0000ff;">"http://cn.com.pansky/SayHiService"</span></span><span>,</span><span class="keyword"><span style="color: #7f0055;">null</span></span><span>); ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>????XFireProxyFactory?serviceFactory?=?</span><span class="keyword"><span style="color: #7f0055;">new</span></span><span>?XFireProxyFactory(); ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>????</span><span class="keyword"><span style="color: #7f0055;">try</span></span><span>{ ??</span>
    </li>
  • <span>??????SayHiService?service?=?(SayHiService)?serviceFactory.create(serviceModel,?serviceURL); ??</span>
  • <span>??????Client?client?=?Client.getInstance(service); ??</span>

  • <li>
    <span>??????</span><span class="comment"><span style="color: #008200;">//client.addOutHandler(new?OutHeaderHandler()); </span></span><span>??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>??????</span><span class="comment"><span style="color: #008200;">//?disable?timeout </span></span><span>??</span>
    </li>
    <li>
    <span>??????client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT,?</span><span class="string"><span style="color: #0000ff;">"1"</span></span><span>); ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>??????String?hello?=?service.sayHi(</span><span class="string"><span style="color: #0000ff;">"张山疯"</span></span><span>); ??</span>
    </li>
    <li>
    <span>??????System.out.println(</span><span class="string"><span style="color: #0000ff;">"服务器对[张山疯]?的回答是:"</span></span><span>?+?hello?); ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>??????hello?=?service.sayHi(</span><span class="keyword"><span style="color: #7f0055;">null</span></span><span>); ??</span>
    </li>
    <li>
    <span>??????System.out.println(</span><span class="string"><span style="color: #0000ff;">"服务器胡言乱语说:"</span></span><span>?+?hello?); ??</span>
    </li>
  • <span>??</span>

  • <li>
    <span>????}?</span><span class="keyword"><span style="color: #7f0055;">catch</span></span><span>?(MalformedURLException?e)?{ ??</span>
    </li>
  • <span>??????e.printStackTrace(); ??</span>
  • <span>????} ??</span>
  • <span>??} ??</span>
  • <span>}??</span>

  • </ol>

    package cn.com.pansky.webservice.xfire.study;
    
    import java.net.MalformedURLException;
    import java.util.Map;
    
    import org.codehaus.xfire.client.Client;
    import org.codehaus.xfire.client.XFireProxyFactory;
    import org.codehaus.xfire.service.Service;
    import org.codehaus.xfire.service.binding.ObjectServiceFactory;
    import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;
    
    public class SayHiClient{
      public static void main(String args[]) {
        String serviceURL = "http://localhost/stove/services/SayHiService";
        Service serviceModel = new ObjectServiceFactory().create(SayHiService.class,null,"http://cn.com.pansky/SayHiService",null);
    
        XFireProxyFactory serviceFactory = new XFireProxyFactory();
    
        try{
          SayHiService service = (SayHiService) serviceFactory.create(serviceModel, serviceURL);
          Client client = Client.getInstance(service);
          //client.addOutHandler(new OutHeaderHandler());
    
          // disable timeout
          client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "1");
    
          String hello = service.sayHi("张山疯");
          System.out.println("服务器对[张山疯] 的回答是:" + hello );
    
          hello = service.sayHi(null);
          System.out.println("服务器胡言乱语说:" + hello );
    
        } catch (MalformedURLException e) {
          e.printStackTrace();
        }
      }
    }
    
    

    ?编译这个类,再执行一下,服务器服务的结果是:

    2008-5-22 17:39:17 org.apache.commons.httpclient.HttpMethodBase writeRequest<br>信息: 100 (continue) read timeout. Resume sending the request<br>2008-5-22 17:39:17 org.apache.commons.httpclient.HttpMethodBase readResponse<br>信息: Discarding unexpected response: HTTP/1.1 100 Continue<br>服务器对[张山疯] 的回答是:张山疯, 你吃了吗?没吃回家吃去吧。<br>2008-5-22 17:39:20 org.apache.commons.httpclient.HttpMethodBase writeRequest<br>信息: 100 (continue) read timeout. Resume sending the request<br>2008-5-22 17:39:20 org.apache.commons.httpclient.HttpMethodBase readResponse<br>信息: Discarding unexpected response: HTTP/1.1 100 Continue<br>服务器胡言乱语说:连名字也不肯告诉我吗?

    好了,WebService布署成功。

    下课!

     
    0
    0
    分享到:
    评论
    1 楼 lvwenwen 2011-12-08  

    相关推荐

      Web Service修炼之一XFire入门3

      在本文中,我们将聚焦于XFire——一个早期的Java Web Service框架,来探讨如何入门Web Service的开发。 XFire是Apache CXF项目的一部分,它提供了一个轻量级、高效且易于使用的API,使得开发者能够快速地创建和部署...

      xfire ibatis spring web service

      这篇博客可能讨论的是如何将这三个技术——XFire、iBatis和Spring——集成在一起,构建一个Web服务应用程序。在这样的集成中,Spring可以管理整个应用的生命周期,包括XFire的Web服务和iBatis的数据访问层。通过...

      xfire--开发WEB SERVICE的又一利器

      【xfire——开发Web服务的又一利器】 Xfire是一款早期用于构建Web服务的开源框架,它为Java开发者提供了一种高效、灵活的方式来创建和消费Web服务。在Web服务领域,Xfire以其轻量级、易于集成和强大的功能集而备受...

      Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务 - ImportNew1

      【Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务】 Web Service是一种基于标准协议的,用于不同系统间交换数据的技术。SOAP(Simple Object Access Protocol)是Web Service常用的一种通信协议,它定义了...

      xfire整合spring发布web services

      【Xfire整合Spring发布Web Services】是将Xfire——一个基于Java的Web服务实现框架,与Spring——一个广泛使用的轻量级应用框架相结合,用于构建和发布Web服务的过程。这个整合使得开发人员能够利用Spring的强大功能...

      第十五章 开发XFire Web Service应用22.pdf

      ### 第十五章 开发XFire Web Service应用22.pdf 知识点解析 #### 15.1 引言 ##### 15.1.1 WebService简介 WebService,中文通常译为Web服务,最初由IBM和微软共同提出的技术规范。它的核心在于提供一个标准化的...

      xfire——webservice具体是实现

      XFire是Java中实现Web服务的一种框架,它允许开发者快速地创建、部署和消费Web服务。本文将详细讲解如何使用XFire来实现Web服务。 1. **XFire的安装与配置** - 首先,你需要下载XFire的支持库,如xfire-...

      WebService xfire学习报告

      **二、XFire——Web Service开发工具** 1. **XFire概述** XFire是一个开源的Java框架,用于构建和消费Web Services。它分为Service、Transport和Invoker三层结构: - **Service层**:负责服务的注册、管理和生命...

      使用XFire发布WebService

      XFire的强大之处在于其易于使用和丰富的功能集,可以方便地处理复杂的Web服务交互。在实际项目中,还可以利用XFire进行更高级的配置,例如添加安全性、事务管理等特性,以满足不同的业务需求。 【标签】: ...

      Web+Services发布与调用(axis,xfire).doc

      《Web服务发布与调用——Axis与XFire详解》 Web服务是互联网上应用程序之间进行交互的一种标准方式,它允许不同系统之间的数据交换,跨越不同的操作系统、编程语言和网络架构。在本文中,我们将深入探讨两种流行的...

      xfire 简要概述

      《XFIRE简要概述——Spring集成实践》 XFIRE,作为一款早期的Web Service框架,为Java开发者提供了便捷的创建和消费Web Service的能力。本文将深入探讨XFIRE与Spring的集成,以及如何构建一个完整的Web Service系统...

      xfire webservices图文介绍详细步骤(附源码)<转>

      这篇博客文章将深入探讨如何使用XFire来构建Web服务,并提供了一个实际的示例项目——webservices_xfire_demo,以帮助开发者更好地理解这个过程。 首先,让我们了解XFire的基本概念。XFire是一个基于JAX-WS标准的...

      webservcie xfire实例

      在本实例中,我们将深入探讨XFire——一个Java Web服务框架,以及如何利用它来创建和消费Web服务。 XFire是早期的Web服务实现之一,它允许开发者快速构建SOAP(Simple Object Access Protocol)服务和客户端。尽管...

      Web+Services发布与调用.doc

      文档"Web+Services发布与调用.doc"详细介绍了如何使用两种不同的工具——Axis和XFire来发布和调用Web Services。 **发布Web Service** 1. **准备工作** - **新建工程**:创建一个新的Java项目,这是所有开发工作...

      xml_webService应用

      在Java环境中,开发和使用XML Web Service有一个常用的框架——xFire(现已被Apache CXF项目合并)。xFire提供了一种简单的方法来创建和消费Web Service,它支持JAX-RPC(Java API for XML-based Remote Procedure ...

      Web Service Cxf

      Apache CXF(Continued eXtension Framework)起源于两个流行的Web服务框架——XFire和Celtix的合并,因此它继承了两者的优势。CXF支持多种协议和标准,包括SOAP、RESTful HTTP、WS-*规范(如WS-Security、WS-...

      xfire+spring+webservice例子

      2. `使用XFire+Spring构建Web Service(一)——helloWorld篇 - 阿蜜果 - BlogJava.mht`:这是一个关于Web服务创建的教程文档,可能详细介绍了如何使用XFire和Spring创建一个简单的"Hello World"服务。 3. `....

      webservice学习笔记 -- XFrie

      【Web Service学习笔记——XFrie框架详解】 Web Service是一种通过网络进行通信的服务,它允许不同的应用程序之间进行数据交换,跨越了操作系统和编程语言的障碍。XFrie是一个轻量级、高性能的Java Web Service框架...

    Global site tag (gtag.js) - Google Analytics