GVKun编程网logo

多次使用axis2调用webservice后,报连接超时错误(axis调用webservice服务)

4

以上就是给各位分享多次使用axis2调用webservice后,报连接超时错误,其中也会对axis调用webservice服务进行解释,同时本文还将给你拓展activitidesigner源码的研究(

以上就是给各位分享多次使用axis2调用webservice后,报连接超时错误,其中也会对axis调用webservice服务进行解释,同时本文还将给你拓展activiti designer源码的研究(一) 采用Axis2调用Webservice、axis,axis2调用.net的webservice、Axis2 webservice 之使用java调用webservice、axis2 发布 webservice 和 java调用webservice等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

多次使用axis2调用webservice后,报连接超时错误(axis调用webservice服务)

多次使用axis2调用webservice后,报连接超时错误(axis调用webservice服务)

多次使用axis2调用webservice后,报连接超时错误

分类: WebService 2011-08-09 16:36 766人阅读 评论(0) 收藏 举报

使用Axis2d的RPCServiceClient调用webservice,连续调用几次web服务后,后台报错,如下所示:

[html] view plain copy
  • org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection  
  •     at org.apache.commons.httpclient.MultiThreadedhttpconnectionManager.doGetConnection(MultiThreadedhttpconnectionManager.java:497)  
  •     at org.apache.commons.httpclient.MultiThreadedhttpconnectionManager.getConnectionWithTimeout(MultiThreadedhttpconnectionManager.java:416)  
  •     at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)  
  •     at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)  
  •     at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)  
  •     at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)  
  •     at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:199)  
  •     at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)  
  •     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)  
  •     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)  
  •     at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)  
  •     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)  
  •     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)  
  •     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)  
  •     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540)  
  •     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521)  
  •     at com.res.rc.client.RPcclient.callService(RPcclient.java:282)  
  •     at com.res.rc.handlers.service.ServiceListHandler.doWebServiceAndReturn(ServiceListHandler.java:337)  
  •     at com.res.rc.handlers.service.ServiceListHandler.process(ServiceListHandler.java:126)  
  •     at com.res.framework.handler.OnlineHandler.handleRequest(UnkNown Source)  
  •     at com.res.framework.servlet.GenericFrameworkServlet.doService(UnkNown Source)  
  •     at com.res.framework.servlet.GenericFrameworkServlet.doPost(UnkNown Source)  
  •     at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)  
  •     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)  
  •     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  
  •     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  •     at com.res.portal.init.SetCharacterEncodingFilter.doFilter(UnkNown Source)  
  •     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)  
  •     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  •     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)  
  •     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)  
  •     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)  
  •     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)  
  •     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)  
  •     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)  
  •     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)  
  •     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)  
  •     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)  
  •     at java.lang.Thread.run(Thread.java:619)  
  • org.apache.axis2.AxisFault: Timeout waiting for connection  
  •     at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)  
  •     at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:203)  
  •     at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)  
  •     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)  
  •     at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)  
  •     at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)  
  •     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)  
  •     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)  
  •     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)  
  •     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:540)  
  •     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:521)  
  •     at com.res.rc.client.RPcclient.callService(RPcclient.java:282)  
  •     at com.res.rc.handlers.service.ServiceListHandler.doWebServiceAndReturn(ServiceListHandler.java:337)  
  •     at com.res.rc.handlers.service.ServiceListHandler.process(ServiceListHandler.java:126)  
  •     at com.res.framework.handler.OnlineHandler.handleRequest(UnkNown Source)  
  •     at com.res.framework.servlet.GenericFrameworkServlet.doService(UnkNown Source)  
  •     at com.res.framework.servlet.GenericFrameworkServlet.doPost(UnkNown Source)  
  •     at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)  
  •     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)  
  •     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  
  •     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  •     at com.res.portal.init.SetCharacterEncodingFilter.doFilter(UnkNown Source)  
  •     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)  
  •     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  
  •     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)  
  •     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)  
  •     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)  
  •     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)  
  •     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)  
  •     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)  
  •     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)  
  •     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)  
  •     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)  
  •     at java.lang.Thread.run(Thread.java:619)  
  • 解决办法:

    [java] view plain copy
  • try  
  • {  
  •     serviceClient = new RPCServiceClient ();  
  •     Options options = serviceClient.getoptions();  
  •     //  指定调用WebService的URL  
  •     EndpointReference targetEPR = new EndpointReference(wsURL);  
  •     options.setTo(targetEPR);  
  •     options.setManageSession(true);   
  •     options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);   
  •     //指定某调用方法的参数值  
  •      Object[] opAddEntryArgs = inParams;  
  •      Class[] classes = outParamClass;  
  •     //  指定要调用的getGreeting方法及WSDL文件的命名空间  
  •       QName opAddEntry = new QName(nameSpace, methodName);  
  •      Object[] result=serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes);  
  •      serviceClient.cleanupTransport();  
  •  }  
  •  catch (AxisFault e)  
  •  {  
  •     e.printstacktrace();  
  •  }  
  •  catch (Exception e)   
  •  {  
  •     e.printstacktrace();  
  •  }  

  • 上述代码中的

    [java] view plain copy
  • options.setManageSession(true);   
  • options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true);   
  • serviceClient.cleanupTransport();  
  • 可以解决多次调用webservice后的连接超时异常
    该错误参照apache官网:

    https://issues.apache.org/jira/browse/AXIS2-4797

    activiti designer源码的研究(一) 采用Axis2调用Webservice

    activiti designer源码的研究(一) 采用Axis2调用Webservice

           最近由于项目的需要,需要对eclipse中的Eclipse Activiti designer插件进行扩充,使其能够调用的webservice,但是遇到了classNotFoundException,我的方法如下:

    <1> 在org.activiti.designer.gui中添加了调用webserviced的类

    <2> 在org.activiti.designer.lib中添加了axis2的jar

    <3> 在org.activiti.designer.lib的manifest.mf中export了axis2

    <4>在org.activiti.designer.gui中manifest.mf中的dependency中添加了lib

    在eclipse中测试run eclipse application时,可以运行,但是导出之后放到rcp rich client中时,会发现访问不到类,说明,不能访问到第三方的jar包


    解决方法:把axis2放到某个目录下,然后直接加载,然后使用反射调用webservice

    public class ServiceUtil {
           //object(Array)转化为String
           public String makeArrayObject(Object array) {
    		List tem = new ArrayList();
    		for (int i = 0; i < Array.getLength(array); i++) {
    			tem.add(Array.get(array,i));
    		}
    		
    		for(int i=0;i<tem.size();i++)
    			System.out.println(tem.get(i));
    		
    		return String.valueOf(tem.get(0));
    	}
    	
    	public String getService(String socketAddress) {
    		String result = null;
    		
    		URL[] urls = new URL[] {};
    		MyClassLoader classLoader = new MyClassLoader(urls,null);
    		
            try {
            	 classLoader.addJar(new File("c:/jar/AXIS2.jar").toURI().toURL());
            	
    			Class rpcserviceclient = classLoader.loadClass("org.apache.axis2.rpc.client.RPCServiceClient");
    			Object rpcserviceclientInstance = rpcserviceclient.newInstance();               
    				
    			Method getoptions = rpcserviceclient.getmethod("getoptions",null);
    			Object c = getoptions.invoke(rpcserviceclientInstance,null);        
    			
    			Class options = c.getClass();
    			
    			Class endpointreference = classLoader.loadClass("org.apache.axis2.addressing.EndpointReference"); 
    			Constructor endpointreferenceCons = endpointreference.getConstructor(String.class);
    			Object endpointreferenceInstance = endpointreferenceCons.newInstance(socketAddress+"ServiceUtil");
    			Method setTo = options.getmethod("setTo",endpointreferenceInstance.getClass());
    			setTo.invoke(c,endpointreferenceInstance);
    			
    			Object[] objects = new Object[] {};
    			Class<?>[] classes = new Class[] { String.class };
    			QName qname = new QName("http://servicemanagement/","getServiceInfo");
    			
    			
    			Method invokebloking = rpcserviceclient.getmethod("invokeBlocking",qname.getClass(),objects.getClass(),classes.getClass());
    			Object obj = invokebloking.invoke(rpcserviceclientInstance,qname,objects,classes);
    
    			result =  makeArrayObject(obj);	
    		} catch (Exception e) {
    			// Todo Auto-generated catch block
    			e.printstacktrace();
    		} 
    		return result;
    	}
    
            class MyClassLoader extends urlclassloader {
    
    	    public MyClassLoader(URL[] urls) {
    	        super(urls);
    	    }
    
    	    public MyClassLoader(URL[] urls,ClassLoader parent) {
    	        super(urls,parent);
    	    }
    
    	    public void addJar(URL url) {
    	        this.addURL(url);
    	    }
    
    	}
    	
    	public static void main(String[]args){
    		String str = new ServiceUtil().getService("http://localhost:8010/ServiceUtil");
    		System.out.println(str);
    	}
    }

    axis,axis2调用.net的webservice

    axis,axis2调用.net的webservice

    今天一个朋友咨询java调用.net的webservice功能,折腾了2个小时,也都折腾出来了,贴出来,希望用到的朋友少走弯路 
    1、axis调用.net的webservice 
    Java代码  

    1. package test;  
    2.   
    3. import java.net.URL;  
    4. import javax.xml.namespace.QName;  
    5. import org.apache.axis.client.Call;  
    6. import org.apache.axis.client.Service;  
    7. import org.apache.axis.encoding.XMLType;  
    8. import javax.xml.rpc.ParameterMode;  
    9. public class Test {  
    10.     static void test() throws Exception{  
    11.         Service service = new Service();  
    12.         Call call = null;  
    13.           try {  
    14.               call = (Call) service.createCall();  
    15.               call.setTargetEndpointAddress(new URL("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"));  
    16.               call.setoperationName(new QName("http://WebXml.com.cn/","getWeatherbyCityName"));  
    17.               call.addParameter("theCityName"),XMLType.soAP_VECTOR,ParameterMode.IN);  
    18.               call.setReturnType(XMLType.soAP_VECTOR);  
    19.               call.setUseSOAPAction(true);  
    20.               call.setSOAPActionURI("http://WebXml.com.cn/getWeatherbyCityName");  
    21.               System.out.println(call.invoke(new Object[]{"广州"}));  
    22.           } catch (Exception e) {  
    23.               e.printstacktrace();  
    24.           }  
    25.     }  
    26.       
    27.     /** 
    28.      * @param args 
    29.      */  
    30. void main(String[] args)          test();  
    31. }  


    2、axis2调用.net的webservice 
       axis2调用不需要写那么多,按照下面的步骤,一步一步来,简单你都想象不到 
       1、下载axis2(到apache官网下载www.apache.org) 
       2、我下载的是axis2-1.5-bin.zip,解压到当前文件夹 
       3、进入bin目录(F:\study\java\service\axis2\axis2-1.5\bin) 
       4、打开cmd,进入第3步的bin目录,输入wsdl2java.bat -uri http://www.webxml.c 
    om.cn/WebServices/WeatherWebService.asmx?wsdl,回车 
       5、之后会在bin目录下生成一个src目录,将src目录下的两个类考到eclipse开发目录下 
       6、建一个测试类Test,代码如下 
    import cn.com.webxml.WeatherWebServiceStub;  
  • import cn.com.webxml.WeatherWebServiceStub.arrayofstring;  
  • import cn.com.webxml.WeatherWebServiceStub.GetWeatherbyCityName;  
  • void test1(){  
  •         try{  
  •             WeatherWebServiceStub stub = new WeatherWebServiceStub();  
  •             stub._getServiceClient().getoptions().setProperty(    
  •                     org.apache.axis2.transport.http.HTTPConstants.CHUNKED,    
  •                     Boolean.FALSE);  
  •             GetWeatherbyCityName city = new GetWeatherbyCityName();  
  •             city.setTheCityName("广州");  
  •             arrayofstring array = stub.getWeatherbyCityName(city).getGetWeatherbyCityNameResult();  
  •             String[] str = array.getString();  
  •             for(String s : str){  
  •                 System.out.println(s);  
  •             }  
  •         }catch(Exception e){  
  •             e.printstacktrace();  
  •         }  
  •         test1();  
  • 需要注意的是这个类 GetWeatherbyCityName ,这个本来是.net webservice中的一个方法,如下 
    POST /WebServices/WeatherWebService.asmx HTTP/1.1  
  • Host: www.webxml.com.cn  
  • Content-Type: text/xml; charset=utf-8  
  • Content-Length: length  
  • SOAPAction: "http://WebXml.com.cn/getWeatherbyCityName"  
  • <?xml version="1.0" encoding="utf-8"?>  
  • <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
  •   <soap:Body>  
  •     <getWeatherbyCityName xmlns="http://WebXml.com.cn/">  
  •       <theCityName>string</theCityName>  
  •     </getWeatherbyCityName>  
  •   </soap:Body>  
  • </soap:Envelope>  

  • 用axis2生成java代码后,会自动生成一个对应的对象,webservice需要传递的参数,可以通过对这个对象赋值操作完成,如上面,我要查广州的天气,就设置为city.setTheCityName("广州"); 
    注意,关键的地方  
    由于.net webservice中返回的是arrayofstring,java中没有这个对象,所以axis2会自动生成这个对象,然后转换成对应的数组即可,如String[] str = array.getString();在axis版本中,使用的是返回类型,但是返回类型设置其他的比如String等都会报错,只能设置成VECTOR,即call.setReturnType(XMLType.soAP_VECTOR),如果只返回一个字符串,可以直接使用STRING;这样才能确保返回正确。 

    比较两个版本,还是觉得axis2使用方便 


    转自http://cqyqing.iteye.com/blog/1668227

    Axis2 webservice 之使用java调用webservice

    Axis2 webservice 之使用java调用webservice

    在上一篇中写了一个简单了webservice,实现了一个sayHello功能。那么webservice写好之后我们如何使用Java程序来调用webservice呢?

    一、java调用的webservice的第一种方式:RPC调用AXIS2 webservice
        下面这个方法是我抽象出来的一个方法,

    import javax.xml.namespace.QName;
    
     org.apache.axis2.AxisFault;
     org.apache.axis2.addressing.EndpointReference;
     org.apache.axis2.client.Options;
     org.apache.axis2.rpc.client.RPCServiceClient;
    
    public class Client {
    
        /**
         * @param args
         * @throws Exception
         */
        static void main(String[] args) throws Exception {
            // 调用PublishWebService
            String wsdlUrl = "http://localhost:8080/DigitalProduct/services/PublishWebService?wsdl";//webservice地址
            String method = "updatePublishSysParam"; //调用的那个方法
            Object[] param = new Object[] { "AASSDDFF" };//传递的参数值
            String namespaceUrl1 = "http://service.digitalproduct.tkbs.com";//命名空间
            Class[] opReturnType1 = new Class[] { String[]. };//返回值类型
            String result = axis2RPCInvoke(wsdlUrl,method,param,namespaceUrl1,opReturnType1);
            System.out.println(result);
        }
    
         * RPC调用AXIS2 webservice
         * 
         *  wsdlUrl
         *            服务地址 如:http://192.168.0.1:2597/aixs2/services/jqservice?wsdl
         *  methodName
         *            方法名 如<xs:element name="Receive">
         *  parameter
         *            方法参数 如Object[] opArgs = new Object[] { param };
         *  namespaceURI
         *            命名空间 如 :targetNamespace="http://server.test.com.cn">
         *  returnType
         *            返回类型 如字符串:Class[] opReturnType = new Class[] { String[].class
         *            };
         static String axis2RPCInvoke(String wsdlUrl,String methodName,Object[] parameter,String namespaceURI,Class[] returnType) {
            Object[] ret = null;
            RPCServiceClient serviceClient = ;
            try {
                /*
                 * 此处RPCServiceClient 对象实例建议定义成类中的static变量 ,否则多次调用会出现连接超时的错误。
                 */
                serviceClient = new RPCServiceClient();
                Options options = serviceClient.getoptions();
                EndpointReference targetEPR =  EndpointReference(wsdlUrl);
                options.setTo(targetEPR);
                QName opQName =  QName(namespaceURI,methodName);
                ret = serviceClient.invokeBlocking(opQName,parameter,returnType);
                 System.out.println(((String[]) ret[0])[0]);
            } catch (AxisFault e) {
                e.printstacktrace();
            }
            return ((String[]) ret[0])[0];
        }
    }

    二、使用java调用webservice的第二种方式:使用myeclipse中的axis2插件生成客户端代码

    new -->others到如下界面:

        点next 到如下界面:

    现在我们想生成调用webservice的客户端代码,首先我们需要生成一个service.wsdl文件,选择第2个,点next,

    在界面里边点击add folder 选择项目--》webroot--》webinf-->classes,输入好webservice那个类的全名后点击Test Class Loading ,这时候如果你选择的路径是对的,类全名是对的,就可以点next,否则next按钮式灰色的。如图:

    然后点击next,这个界面中的内容基本不用修改,有一个service name,你可以改成你自己取。

    继续点next 在界面中选择wsdl文件的输出路径,选择第一个,就是输出到当前的workspace,的某个项目下,选择第二个,就是输出到系统文件夹中,例如你可以选择桌面。

    这里我选择第二个,然后点browse选择桌面,点finish,会看到桌面上有一个service.wsdl文件。

     

    下面我们就可以根据这个wsdl文件生成客户端代码了。

    首先建一个java项目,例如取名myclient

    new -->others-->

    选择第1个,点next.

    在界面中点 browse找到你刚才生成service.wsdl文件。

    点next,这个界面不用管,继续点next

    这个时候需要选择代码生成的地方,选择当前工作的workspace,然后选择刚才新建的myclient如图:

    点finsh,刷新myclient项目会看到src下多了两个java文件:TestServiceCallbackHandler   和 TestServiceStub

    接下来就可以写java代码调用了,如下:

     myservice.service.TestServiceStub;
    
     Test {
    
         Exception 
          Todo Auto-generated method stub
            初始化Sub类
            TestServiceStub stub =  TestServiceStub();
            传递AxisServiceStub.ShowName对象,相关参数在这边赋值。
            TestServiceStub.SayHello command =  TestServiceStub.SayHello();
            command.setName("zhangsan");
            取得返回值
            String name = stub.sayHello(command).get_return();
            System.out.println(name);
        }
    
    }

     

    如此,第二种方式就写完了。

    公司几个同事都喜欢第二种。但是,我个人喜欢用第一种。第二种方式如果插件使用熟练的话,很快就可以生产客户端代码,然后测试代码也可以很快写出来。

    注:可能会出现错误,根据我的经历的错误经验,有以下情况:

        1.tomcat端口问题,你打开刚才插架自动生成的TestServiceStub 类 ctrl+f查找 http://localhost,查到后看他后面的端口是多少,是不是8080,?好像生成的就是8080,但是我们的tomcat可能被自己修改过,端口可能不是8080,所以这里你要改这个端口。

        2.spring的注入问题,如果你写的webservice是在spring整合的环境下,可能会报错误,一般是由 spring注入失败,导致xxxService类注入失败。关于这个我下一篇会详细解释。

        3.一切都正常,打断点调试看到方法执行成功了、执行完毕了,但是并没有成功的返回我们要的结果,而是报超时了,这时候,我们需要在TestServiceStub 中加入一行代码

            这行代码的作用是 规定超时时间 是多长,例如你可以设为10分钟。_operationClient.getoptions().setTimeOutInMilliSeconds(600000L);  //600*1000毫秒(10分钟

          我感觉这样设置不合理,但是可以解决这个错误,让你的程序运行成功,看到运行成功返回的结果。才有继续学习的劲头啊。

       

     

     

     

    axis2 发布 webservice 和 java调用webservice

    axis2 发布 webservice 和 java调用webservice

    1.下载与安装axis2:
    apache-tomcat-6.0.35.zip
    axis2-1.6.1-war.zip
    解压,然后将axis2.war复制到tomcat的webapp目录中,安装完毕!
    启动tomcat测试axis2是否安装成功:
    http://localhost:8080/axis2

    2.首先简单介绍一下webapp/axis2/的目录结构如下:
    axis2
      |-- axis2-web
      |      |-- xxx.jsp...
      |-- meta-inf
      |-- WEB-INF
      |      |-- classes
      |      |-- conf
      |      |-- lib
      |      |-- modules
      |      |-- services
      |      |      |-- version-1.6.1.aar
      |      |-- web.xml
    其中,services目录就是用来发布webservice的目录,这里有一个自带的service:version-1.6.1.aar

    3.开发service端:HelloService .java
    package com.service;
    public class HelloService {
    	public String getName(String name) {
    		return "hello: " + name;
    	}
    }

    4.配置文件:service.xml
    <service name="HelloService">
    	<description>HelloWorld webservice</description>
    	<parameter name="ServiceClass">
    		com.service.HelloService
    	</parameter>
    	<messageReceivers>
    		<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"https://www.jb51.cc/tag/cme/" target="_blank">cmessageReceiver"/>
    		<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"/>
    	</messageReceivers>
    </service>

    5.建立如下的目录结构:
    test
     |--  meta-inf
     |      |--services.xml
     |
     |--  com
     |      |--  service
     |              |--  HelloService.java
     |              |--  HelloService.class
    这里test可以随便命名,然后要把test目录里面的所有文件打包成zip格式的,后缀必须是*.aar。
    打包方法1,使用7-Zip压缩工具打包,格式选择zip,压缩之后,把文件的后缀改为aar,test.aar。
    打包方法2,其实“con/...”这个部分是class文件,可以放入/webapps/WEB-INF/class目录下。也就是说打包的时候可以之打包“meta-inf/...”部分。而“con/...”部分可能会经常更改,在Eclipse开发过程中可以放入src目录中。
    打包完成之后,然后将文件test.aar复制到services目录下面。重启tomcat,进行测试:
    http://localhost:8080/axis2/services/listServices

    6.开发客户端:RPcclient.java
    package com.client;
    
    import javax.xml.namespace.QName;
    import org.apache.axis2.addressing.EndpointReference;
    import org.apache.axis2.client.Options;
    import org.apache.axis2.rpc.client.RPCServiceClient;
    
    public class RPcclient {
    	public static void main(String[] args) throws Exception {
    		RPCServiceClient client = new RPCServiceClient();
    		Options options = client.getoptions();
    		// 指定调用WebService的URL
    		options.setTo(new EndpointReference("http://localhost:8080/axis2/services/HelloService"));
    
    		// 指定getName方法的参数值
    		Object[] objects = new Object[] { "超人" };
    		// 指定getName方法返回值的数据类型的Class
    		Class<?>[] classes = new Class[] { String.class };
    		// 指定要调用的方法名:getName 和 WSDL文件中的命名空间:http://service.com
    		// 注意:命名空间(http://service.com)与类HelloService的包名(com.service)有一定关系。
    		QName qname = new QName("http://service.com","getName");
    
    		String result = (String) client.invokeBlocking(qname,objects,classes)[0];
    		System.out.println(result);
    	}
    }

    7.运行客户端,端测试结果: 你好 超人

    关于多次使用axis2调用webservice后,报连接超时错误axis调用webservice服务的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于activiti designer源码的研究(一) 采用Axis2调用Webservice、axis,axis2调用.net的webservice、Axis2 webservice 之使用java调用webservice、axis2 发布 webservice 和 java调用webservice等相关知识的信息别忘了在本站进行查找喔。

    本文标签:

    上一篇webservice的原理及概念(webservice基本原理)

    下一篇WebService之--------Axis2准备工作(axis2 webservice)