Summary of four release methods of WebService

WebServiceSummary of four publishing methods


1.CXFMethod

CXFandspringBuildwebserviceis currently the most popular method, but it is rumoredcxfandjdk1.5There are some incompatibility, I have not encountered it, I have encountered The problem is cxfandwas6.1.1incompatible, manifested incxfRequiredjar< span style="margin:0px; padding:0px; font-family:宋体">package “wsdl4j-1.6.2.jar” reports an error, the error reported is: java.lang.IncompatibleClassChangeError, obviously jarPackage incompatibility problem, it’s very true I had a headache, and later I searched for information and found a solution to the abovejarCreate a new packagewasShared library can be solved, but the customer manager Zhou does not want to use this method because it needs to be modifiedwas, so I switched toaxis2The method will be introduced below. Make a record of this problem here and use it latercxfandwasPlease pay attention to it! ! !

Use cxf+springBuildWebService:

The first step, add jar package. Note here that different environments (tomcatwas)jaris not necessarily the same, such as my localcxf+springjust as followsjarPackage:

while Taikang wasThe environment needs to be as follows jarpackage :

Obviously a lot more, the reason should be the serverjar The package pool is different. Just fill in what is missing according to the error message, pay attentionjarDo not repeat the package.

The second step, configuration web.xmlThe files are as follows (Important places have been marked):

<context-param>

<param-name> contextConfigLocationparam -name>

<param-value>classpath:/applicationContext.xml< /span>param-value>

context-param>

<listener> <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class span>>

listener>

<filter>

<filter-name>encodingFilterfilter-name>

<filte r-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>

<init-param>

<param-name>encodingparam-name>

<param-value>UTF-8param-value< /span>>

init-param>

filter>

<filter-mapping>

<filter-name>encodingFilterfilter-name>

<< /span>url-pattern>/*url-pattern>

filter-mapping>

<servlet>

<servlet-name>CXFServletservlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServletservlet-class>

<load-on-startup>1 load-on-startup>

servlet>

<servlet -mapping>

<servlet-name>CXFServletservlet-name>< /p>

<url-pattern>/webservice/*url-pattern span>>

servlet-mapping span>>

In the place marked above, the first place is spring configuration file path; second Yeswsdl Address content;


< /p>

The third step, write interface classes and implementation classes , Pay attention to the comments

interface class

@WebService< /p>

public interface SendService {

public boolean sendOA(@WebParam(name=”param “)String param);

publicboolean sendOrg(OrgEntity org);< /p>

}

implementation class

< span style="">@WebService(endpointInterface=”com.service.SendService”,serviceName=”sendService”)

publicclass SendServiceImpl implements SendService{

public boolean sendOA(String param) {

System.out.println(“——-sendOA— ——param:”+param);

if(param.equals(“zhoujian”)){

returntrue;

}

returnfalse;

}

public boolean sendOrg(OrgEntity org) {

System.out.println(“——-sendOrg–begin——-“);

return true;

}

}

第四步< /span>,Spring配置文件

xml version=“1.0” encoding=“UTF-8”?>

<beans

xmlns=“http://www.springframework.org/schema/beans”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns:p=“http://www.springframework.org/schema/p”

xmlns:jaxws=“http://cxf.apache.org/jaxws”

    xsi:schemaLocation=

      http://www.springframework.org/schema/beans

      http://www.springframework.org/schema/beans/spring-beans.xsd

      http://cxf.apache.org/jaxws

      http://cxf.apache.org/schemas/jaxws.xsd”>

<import resource=“classpath:META-INF/cxf/cxf.xml”/>

    <import resource=“classpath:META -INF/cxf/cxf-extension-soap.xml”/>

   <import resource=“classpath:META-INF/cxf/cxf-servlet.xml”/>

  

   <jaxws:endpoint id=sendServie implementor=com.service.impl.SendServiceImpl 

address=/sendServie />

 

 

beans>

“jaxws:client”该标签可以不必写,访问时可以手动拼接该url

第五步,发布,直接部署到服务器,访问:

http://10.137.138.11:9080/Wb/webservice/sendServie?wsdl

 


2. Xfire方式

据说xfire方式已经很老了,但个人感觉,xfire方式很简单且容易配置,不知为啥过时了,也没感觉cxfaxis2哪里先进,我当时卡在cxfwas搞不定时想尝试xfire方式被周经理给拒绝了。

Xfire方式发布webservice

第一步,添加jar包,如下:

 

第二步,修改web.xml文件

    XFireServlet

    org.codehaus.xfire.transport.http.XFireConfigurableServlet

    0

  

  

    XFireServlet

    /services/*

  

第三步,编写接口类

接口类:

public abstract interface IBankingService {

public abstract String transferFunds(String paramString1);

}

实现类:

public class BankingService implements IBankingService{

  public String transferFunds(String fromAccount)

  {

    return fromAccount+”:ok”;

  }

}

第四步,编写services.xml配置文件

WEB-INF目录下新建目录META-INF,在该目录下新建文件夹xfire,该目录下新建文件services.xml

xml version=“1.0” encoding=“UTF-8”?>

<beans xmlns=“http://xfire.codehaus.org/config/1.0”>

<service>

<name>Bankingname>

<namespace>mybanknamespace>

<serviceClass>

com.mybank.xfire.example.IBankingService

serviceClass>

<implementationClass>

com.mybank.xfire.impl.BankingService

implementationClass>

service>

beans>

第五步,发布,部署到服务器,访问url:

http://localhost:9080/Xfire/services/Banking?wsdl

 


3. AXIS2方式

Axis2发布WebService有两种方式,其一是利用axis2插件打成aar包放到axis_war里面部署到服务器发布;其二是不打包发布(本例);我不清楚打包发布有什么好处,感觉很麻烦项目外还得部署一个war,现在介绍第二种不打包的方式,类似xfire,同时由于cxfwas不兼容导致wsdl.jar报错,但是xfireaxis2也用到wsdl.jar却不报错,我个人也是很费解,泰康项目目前使用的就是axis2方式。

Axis2发布WebService

第一步,添加jar包,如下:

 

很多是吧,不过都是从axis.war里面WEB-INF下的lib目录复制来的。

第二步,修改web.xml文件

<servlet>

        <servlet-name>AxisServletservlet-name>  <servlet-class>org.apache.axis2.t ransport.http.AxisServletservlet-class>

        <load-on-startup>1load-on-startup>

    servlet>

    <servlet-mapping>

        <servlet-name>AxisServletservlet-name>

        <url-pattern>/services/*ur l-pattern>

    servlet-mapping>

 

 


第三步,编写实现类

public class ServiceImpl {

public String sayHello(String name){

System.out.println(“================”);

return “hello:”+name;

}

}

第四步,增加WEN-INF内容

axis.war解压下的WEN-INF文件夹内的confmodules复制到项目WEB-INF

 

第五步,WEB-INF下创建文件夹services(名字不可改),在该目录下创建文件夹(名称随意),在该目录下创建文件夹META-INF(名称不可改),在该目录下创建文件services.xml(名称不可改),该文件内容为:

xml version=“1.0” encoding=“UTF -8”?>

<service name=“axisDemo”>

    <description>

        Web Service例子

    description>

    <parameter name=“ServiceClass”>

        com.ServiceImpl

    parameter>

    <messageReceivers>

        <messageReceiver mep=“http://www.w3.org/2004/0 8/wsdl/in-out”

            class=“org.apache.axis2.rpc.receivers.RPCMessageReceiver” />

        <messageReceiver mep=“http://www.w3.org/2004/08/wsdl/in-only”

       class=“org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver” />

    messageReceivers>

service>

 

第六步,部署到服务器,发布URL为:

http://localhost:9080/Axis2Test/services/axisDemo?wsdl

 


4. AXIS1方式

同上,不知道AXIS1哪里不好,配置也很简单,如下:

第一步,添加jar

 

第二步,修改web.xml

<servlet>

    <servlet-name>AxisServletservlet-name>

    <servlet-class>

        org.apache.axis.transport.http.AxisServlet

    servlet-class>

  servlet>

  <servlet-mapping>

    <servlet-name>AxisServletservlet-name>

    <url-pattern>/services/*url-pattern>

  servlet-mapping>

第三步,实现类与实体类

实现类:

package com;

public class Axis {

public String sayHello(String name){

System.out.println(“============:”+name);

return “hi:”+name;

}

public String sayHelloToUser(User u){

System.out.println(“============:”+u.getId());

System.out.println(“============:”+u.getPath());

System.out.println(“============:”+u.getAdd());

return “hi:”+u.getName();

}

}

 

 

实体类:

package com;

public class User {

private String id;

private String name;

private String add;

private String path;

    

    getter setter ……方法

 

第四步,创建配置文件:在WEB-INF下新建文件“server-config.wsdd”

xml version=“1.0” encoding=“UTF-8”?>

<deployment xmlns=“http://xml.apache.org/axis/wsdd/”

         xmlns:java=“http://xml.apache.org/axis/wsdd/providers/java”>

 

Leave a Comment

Your email address will not be published.