axis调用jax-ws开发的webservice有关问题(急)
axis调用jax-ws开发的webservice问题(急!!!!)
在和其他公司联调的时候,我开发的webservice是基于jax-ws,对方使用axis调用,在联调的时候,调用没有问题,不过在对方要等好久才能收到返回的消息,我打印了下时间间隔,差不多要5分钟,我在自己电脑上测试也出现类似的问题,不过不知道具体哪个环节出了问题。现在这个问题也比较急,希望大家能够给点帮助。我把写得测试代码贴出来,大家看看有没有什么问题。
接口:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
/**
* 服务接口 通过注解@WebService标明当前接口声明一个webservice
* 通过注解@WebMethod将接口的方法声明为webservice中向外暴露的方法
*
* @author dgl
* @version 1.0.0
*/
@WebService
@SOAPBinding(style = Style.RPC)
public interface TimeService {
/**
* 返回从1970年1月1日0点0时0分起的毫秒数
*
* @return
*/
@WebMethod
@WebResult(name="time")
public String getTimeAsString(@WebParam(name="test")String test);
/**
* 返回如“2009-12-21”格式的日期
*
* @return
*/
@WebMethod
public long getTimeAsElapsed();
}
实现:
import java.text.DateFormat;
import java.util.Date;
import javax.jws.WebService;
/**
* webservice接口实现类
* @author dgl
* @version 1.0.0
*/
@WebService(endpointInterface = "com.dgl.webservice.TimeService")
public class TimeServiceImpl implements TimeService {
@Override
public long getTimeAsElapsed() {
return new Date().getTime();
}
@Override
public String getTimeAsString(String test) {
System.out.println(test);
Date date = new Date();
DateFormat df = DateFormat.getDateInstance();
return df.format(date);
}
}
发布:
import javax.xml.ws.Endpoint;
import com.dgl.webservice.TimeServiceImpl;
/**
* 向外发布webService
* @author dgl
* @version 1.0.0
*/
public class TimeServicePublicer {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8888/service", new TimeServiceImpl());
System.out.println("public success");
}
}
测试:
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class AxisTest {
/**
* TODO
*
* @param args
*/
public static void main(String[] args) {
String url = "http://localhost:8888/services/TimeService";
Service service = new Service();
try {
org.apache.axis.client.Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(url));
call.setOperationName(new QName("http://webservice.dgl.com/",
"getTimeAsString"));
call.addParameter("test", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
long startTime = System.currentTimeMillis();
String test = "test";
String time = (String) call.invoke(new Object[] { test });
System.out.println(time.toString());
System.out.println(System.currentTimeMillis() - startTime);
} catch (Exception e) {
e.printStackTrace();
}
}
}
------解决方案--------------------
我也遇到了,
最简单的应用,根本不会耗时。但是就是在call.invoke(new Object[] { test });时卡住了。要等好几分钟才会有返回结果。服务端立马返回了结果,但是客户端就是在等待中。
我查过很多资料有的说因为服务端和客户端采用的底层协议不一致或者说http版本不一致,一个是http1.0,一个是http1.1但是没有结果
在和其他公司联调的时候,我开发的webservice是基于jax-ws,对方使用axis调用,在联调的时候,调用没有问题,不过在对方要等好久才能收到返回的消息,我打印了下时间间隔,差不多要5分钟,我在自己电脑上测试也出现类似的问题,不过不知道具体哪个环节出了问题。现在这个问题也比较急,希望大家能够给点帮助。我把写得测试代码贴出来,大家看看有没有什么问题。
接口:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
/**
* 服务接口 通过注解@WebService标明当前接口声明一个webservice
* 通过注解@WebMethod将接口的方法声明为webservice中向外暴露的方法
*
* @author dgl
* @version 1.0.0
*/
@WebService
@SOAPBinding(style = Style.RPC)
public interface TimeService {
/**
* 返回从1970年1月1日0点0时0分起的毫秒数
*
* @return
*/
@WebMethod
@WebResult(name="time")
public String getTimeAsString(@WebParam(name="test")String test);
/**
* 返回如“2009-12-21”格式的日期
*
* @return
*/
@WebMethod
public long getTimeAsElapsed();
}
实现:
import java.text.DateFormat;
import java.util.Date;
import javax.jws.WebService;
/**
* webservice接口实现类
* @author dgl
* @version 1.0.0
*/
@WebService(endpointInterface = "com.dgl.webservice.TimeService")
public class TimeServiceImpl implements TimeService {
@Override
public long getTimeAsElapsed() {
return new Date().getTime();
}
@Override
public String getTimeAsString(String test) {
System.out.println(test);
Date date = new Date();
DateFormat df = DateFormat.getDateInstance();
return df.format(date);
}
}
发布:
import javax.xml.ws.Endpoint;
import com.dgl.webservice.TimeServiceImpl;
/**
* 向外发布webService
* @author dgl
* @version 1.0.0
*/
public class TimeServicePublicer {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8888/service", new TimeServiceImpl());
System.out.println("public success");
}
}
测试:
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class AxisTest {
/**
* TODO
*
* @param args
*/
public static void main(String[] args) {
String url = "http://localhost:8888/services/TimeService";
Service service = new Service();
try {
org.apache.axis.client.Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(url));
call.setOperationName(new QName("http://webservice.dgl.com/",
"getTimeAsString"));
call.addParameter("test", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
long startTime = System.currentTimeMillis();
String test = "test";
String time = (String) call.invoke(new Object[] { test });
System.out.println(time.toString());
System.out.println(System.currentTimeMillis() - startTime);
} catch (Exception e) {
e.printStackTrace();
}
}
}
------解决方案--------------------
我也遇到了,
最简单的应用,根本不会耗时。但是就是在call.invoke(new Object[] { test });时卡住了。要等好几分钟才会有返回结果。服务端立马返回了结果,但是客户端就是在等待中。
我查过很多资料有的说因为服务端和客户端采用的底层协议不一致或者说http版本不一致,一个是http1.0,一个是http1.1但是没有结果