`
lewking
  • 浏览: 9795 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

axis webservice (service.xml)

阅读更多
Myeclipse9.X 搭建 axis2  WebService

SetupWebService.java
/**
 * WebService.java
 * com.lewking.service
 *
 * Function: TODO 
 *
 *   ver         date      	    author
 * ──────────────────────────────────────
 *  Ver 1.1	     2011-6-9 	    lewking
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/

package com.lewking.service;

import org.apache.log4j.Logger;

/**
 * ClassName:WebService
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   lewking
 * @version  
 * @since    Ver 1.1
 * @Date	 2011-6-9		下午09:44:41
 * 
 * @see 	 
 * @ deprecated 
 */
public class SetupWebService {
	Logger logger = Logger.getLogger(SetupWebService.class.getName());
	private String msg;
    
	public String welcome(String t){
		logger.info("---" + t + msg);
		return t + msg;
	}
	
    public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}

applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

	 <bean id="lewkingService" class="com.lewking.service.SetupWebService">
	  <property name="msg">
	      <value>Hello World</value>
	  </property>
	 </bean>

</beans>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
   <servlet>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>
		org.apache.axis2.transport.http.AxisServlet</servlet-class>
  </servlet>
  <servlet>
    <display-name>
		Apache-Axis Admin Servlet Web Admin</display-name>
    <servlet-name>AxisAdminServlet</servlet-name>
    <servlet-class>
		org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
    <load-on-startup>100</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>AxisAdminServlet</servlet-name>
    <url-pattern>/axis2-admin/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>/axis2-web/index.jsp</welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>404</error-code>
    <location>/axis2-web/Error/error404.jsp</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/axis2-web/Error/error500.jsp</location>
  </error-page>
  <servlet>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-name>AdminServlet</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AdminServlet</servlet-name>
    <url-pattern>/servlet/AdminServlet</url-pattern>
  </servlet-mapping>
  
  <!-- spring 监听器 -->
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>WEB-INF/applicationContext.xml</param-value>
  </context-param>
</web-app>

在web-inf 下建 services/webservice/META-INF/services.xml 内容如下
 
<!--web service 名称-->
<service name="lewking" targetNamespace="http://service.lewking.com/">
	<Description>
		Please Type your service description here
	</Description>
	<parameter name="ServiceObjectSupplier">
        org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
    </parameter>
    <!-- spring bean Id-->
    <parameter name="SpringBeanName" locked="false">lewkingService</parameter>
 <!-- webservice 类的完全路径-->
	<parameter name="ServiceClass" locked="false">com.lewking.service.SetupWebService</parameter>
	<messageReceivers>
          <!--表示有参没有返回值的方法-->
		<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
         <!--表示有参有返回值的方法-->
		<messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
	</messageReceivers>
	<excludeOperations>    
    <operation></operation>
    </excludeOperations>
</service>


如果启动时遇到异常:
- The service cannot be found for the endpoint reference (EPR) /webservices/services
org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) /webservices/services
	at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:65)
	at org.apache.axis2.engine.Phase.invoke(Phase.java:333)
	at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
	at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)
	at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)
	at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)
	at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)
	at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)


解决:
     把 WEB-INF 下的index.jsp 删除, 将 axis2.war 里的 axis2-web 目录拷贝到 webroot 目录下,就OK

Test Code:
/**
 * WebServiceTest.java
 * com.lewking.test
 *
 * Function: TODO 
 *
 *   ver         date      	    author
 * ──────────────────────────────────────
 *  Ver 1.1	     2011-6-8 	    lewking
 *
 * Copyright (c) 2011, TNT All Rights Reserved.
*/
package com.lewking.test;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.junit.Test;
/**
 * ClassName:WebServiceTest
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   lewking
 * @version  
 * @since    Ver 1.1
 * @Date	 2011-6-8		下午11:24:34
 * 
 * @see 	 
 * @ deprecated 
 */
public class WebServiceTest {
	@Test
	public void test() throws ServiceException, RemoteException, MalformedURLException{
		String endpoint ="http://localhost:8080/webservices/services/lewking?wsdl";
		 Service service = new Service();
		   Call call = (Call) service.createCall();

		   call.setTargetEndpointAddress(new java.net.URL(endpoint));
		   call.setOperationName(new QName("http://service.lewking.com","welcome"));

		   String ret = (String) call.invoke(new Object[] {"Samland"});

		   System.out.println("Sent 'Hello!', got '" + ret + "'");
		
	}
}

分享到:
评论

相关推荐

    Axis webService 教程.pdf

    ### Axis WebService 教程知识点总结 #### 一、如何发布自己的WebService ##### 1.1 即时发布 JWS (Java Web Service) Files - Instant Deployment - **定义**: 即时发布是一种快速简便的方式,它允许直接通过将...

    JAVA调JAVA调用webservice(axis方式).doc 用webservice(axis方式).doc

    示例代码中的导入语句包括`javax.xml.namespace.QName`、`org.apache.axis.client.Call`和`org.apache.axis.client.Service`等,这些都是调用WebService所必需的。 ```java import javax.xml.namespace.QName; ...

    Axis2之使用services.xml发布带包的Webservice

    标题中的“Axis2之使用services.xml发布带包的Webservice”指的是在Apache Axis2框架下,通过services.xml配置文件来发布包含多个类或包的Web服务。Apache Axis2是Java平台上的一个开源Web服务框架,它允许开发人员...

    javax.xml.rpc

    "javax.xml.rpc"是Java平台中的一个关键组件,主要用于实现基于XML的远程过程调用(XML-RPC)服务。这个框架允许Java应用程序通过HTTP协议来调用远程服务器上的方法,从而实现分布式计算。在Java EE环境中,它常与...

    利用AXIS开发Webservice教程.doc

    import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class Test { public static void main(String[] args) throws Exception { String ...

    手把手教你创建axis-webservice.docx

    import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class Test { public static void main(String[] args) throws Exception { String ...

    Axis开发WebService实例.pdf

    **创建代理对象**:在客户端程序`TestHelloClient`中,使用`javax.xml.rpc.ServiceFactory`创建一个`Service`对象,然后根据WSDL文件创建代理对象。 3. **调用服务方法**:通过代理对象调用`getName`方法,并处理...

    eclipse+AXIS开发webservice.pdf

    【标题】: 使用Eclipse和AXIS开发WebService的步骤详解 【描述】: 本文档详细介绍了如何利用Eclipse集成开发环境和AXIS框架来创建并发布WebService。 【标签】: Eclipse 【部分内容】: 在开发基于Java的...

    Tomcat+Axis实现webservice.doc【CSDN精品推荐】

    &lt;deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"&gt; &lt;service name="AxisReturn" provider="java:RPC"&gt; ...

    axis webservice开发过程.doc

    【Axis Webservice 开发过程详解】 在Web服务领域,Axis是一个流行且强大的工具,用于创建和部署基于Java的Web服务。本文将详细讲解如何使用Axis进行Web服务开发,包括概念理解、环境准备、接口与实现类创建、配置...

    使用axis自动生成webservice客户端代码.pdf

    public webservice.axis.test.batClient.HelloWorld getHelloWorld() throws javax.xml.rpc.ServiceException; } // HelloWorldServiceLocator.java package webservice.axis.test.batClient; public class ...

    WebService之AXIS传递javabean.7z

    2. **生成Java stubs**:使用AXIS的WSDL2Java工具,你可以从Web服务的WSDL(Web Service Description Language)文件生成Java客户端和服务器端的存根(stubs)。这将为你的javabean创建对应的类型,并实现服务调用所...

    MyEclipse 8.5 Axis2 插件完整jar包开发webservice

    MyEclipse 8.5 安装 Axis2 插件...--org.apache.axis2.eclipse.service.plugin_1.6.2.jar --javax.xml.bind_2.1.9.v201005080401.jar --javax.xml.stream_1.0.1.v201004272200.jar --javax.xml_1.3.4.v201005080400.jar

    Axis2开发webservice总结.doc

    1. **Web Service技术介绍** Web服务是一种基于互联网的软件应用程序接口,它允许不同系统之间的数据交换。在Axis2中,Web服务的消息内容遵循SOAP(Simple Object Access Protocol)标准,其编码方式通常为...

    webservice培训.ppt

    WebService的核心概念是服务提供者和服务消费者,服务提供者发布服务,服务消费者通过特定的描述语言(WSDL,Web Service Description Language)找到并调用这些服务。 WebService的工作原理: 1. 服务提供者创建一...

Global site tag (gtag.js) - Google Analytics