webservice的配置(axis)

web系统中通常我们需要为其他系统提供webservice服务,其中依赖jar包文件不做详细描述。

现在就基本配置步骤总结如下:

配置1:在web.xml文件中增加如下代码。

<!-- 配置websercice服务的servlet -->

<servlet>

<servlet-name>AxisServlet</servlet-name>

<servlet-class>

org.apache.axis.transport.http.AxisServlet

</servlet-class>

</servlet>

<servlet>

<servlet-name>AdminServlet</servlet-name>

<servlet-class>

org.apache.axis.transport.http.AdminServlet

</servlet-class>

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

</servlet>

<servlet>

<servlet-name>SOAPMonitorService</servlet-name>

<servlet-class>

org.apache.axis.monitor.SOAPMonitorService

</servlet-class>

<init-param>

<param-name>SOAPMonitorPort</param-name>

<param-value>5001</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>/servlet/AxisServlet</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>*.jws</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

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

</servlet-mapping>

<servlet-mapping>

<servlet-name>SOAPMonitorService</servlet-name>

<url-pattern>/SOAPMonitor</url-pattern>

 </servlet-mapping>

配置2:在WEB-INF目录下增加server-config.wsdd文件,其中内容为我们需要发布的service服务对象。

<?xml version="1.0" encoding="UTF-8"?>

<deploymentxmlns="http://xml.apache.org/axis/wsdd/"xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<globalConfiguration>

<parametername="sendMultiRefs"value="true"/>

<parametername="disablePrettyXML"value="true"/>

<parametername="adminPassword"value="admin"/>

<parametername="dotNetSoapEncFix"value="true"/>

<parametername="enableNamespacePrefixOptimization"value="true"/>

<parametername="sendXMLDeclaration"value="true"/>

<parametername="attachments.implementation"value="org.apache.axis.attachments.AttachmentsImpl"/>

<parametername="sendXsiTypes"value="true"/>

<requestFlow>

<handlertype="java:org.apache.axis.handlers.JWSHandler">

<parametername="scope"value="session"/>

</handler>

<handlertype="java:org.apache.axis.handlers.JWSHandler">

<parametername="scope"value="request"/>

<parametername="extension"value=".jwr"/>

</handler>

</requestFlow>

</globalConfiguration>

<handlername="LocalResponder"type="java:org.apache.axis.transport.local.LocalResponder"/>

<handlername="URLMapper"type="java:org.apache.axis.handlers.http.URLMapper"/>

<handlername="Authenticate"type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>

<transportname="http">

<requestFlow>

<handlertype="URLMapper"/>

<handlertype="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>

</requestFlow>

<parametername="qs:wsdl"value="org.apache.axis.transport.http.QSWSDLHandler"/>

<parametername="qs.list"value="org.apache.axis.transport.http.QSListHandler"/>

<parametername="qs:method"value="org.apache.axis.transport.http.QSMethodHandler"/>

<parametername="qs.wsdl"value="org.apache.axis.transport.http.QSWSDLHandler"/>

</transport>

<transportname="local">

<responseFlow>

<handlertype="LocalResponder"/>

</responseFlow>

 </transport>

<service name="UserWebService" type="" regenerateElement="true"

provider="java:RPC"style="rpc"use="encoded">

<parametername="scope"value="Request"regenerateElement="false"/>

<parametername="className"value="com.demo.webservice.UserWebService"regenerateElement="false"/>

<parametername="allowedMethods"value="getUserNameById"regenerateElement="false"/>

</service>

完成上述的两个步骤即可完成werbservice的配置,但是具体的service的实现类。根据各自需求完成,这里贴出一部分简要代码

package com.demo.webservice;

/**

*<p>Title:用户信息的webservice测试类</p>

*/

public class UserWebService extends ServletEndpointSupport implements IUserWebService{

//注意,此处不能通过ioc的方式进行依赖注入,只能通过下面的方式获取到userService的对象。然后进行service层调用(前提是getBean("userService")的userService已经在spring的配置文件中进行了配置)

 private IUserService userService;

protectedvoidonInit()

{

userService=(IUserService)getApplicationContext().getBean("userService");

}

publicStringgetUserNameById(StringuserId)

{

System.out.println("getUserNameById=123=="+userId);

Stringusername="fafa";

Useruser=userService.findUserById(userId);

userName=user.getUsername();

System.out.println("getUserNameById=123==userName:"+userName);

returnuserName;

}

}

注意:由于我们的UserWebService 应用了spring的依赖注入,所以其中多了一项public void setUserService的方法,在发布时通过http://localhost:8080/sshdemo/services/UserWebService?wsdl查看生成的wsdl文件时会报错:Namespace   prefixes   must   be   set   on   the   Definition   object   using   the   addNamespace(...)   method.:  

faultActor:

faultNode:

  faultDetail:  

,而我们在发布websercice的时候配置文件中allowedMethods的value值应该只指定我们需要暴漏的方法getUserNameById,而不能用*号代替,否则会出错。

一个简单的webservice应用就配置发布好了。通过上面的链接可以查看到生成的xml文件即表示成功。祝你好运。

  

相关推荐