我第一次接触webservice,怎么调用用web service接口,cxf或者axis2都行,网上找的例子,都有点错误 50
try{JaxWsDynamicClientFactoryfactory=JaxWsDynamicClientFactory.newInstance();Clientcl...
try {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient("xxxxxxxxx");//wsdl地址,比如http://xxxxxx/xxx?.wsdl
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
Request request = new Request();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2014, 3, 18,
DatatypeConstants.FIELD_UNDEFINED);
request.setCurrentDt(xmlDate);
Object[] objs = client.invoke("xxxxxxxxxxxxx", request);
System.out.println(objs[0].toString());
} catch (Exception e) {
// TODO: handle exception
} 展开
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient("xxxxxxxxx");//wsdl地址,比如http://xxxxxx/xxx?.wsdl
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
Request request = new Request();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(2014, 3, 18,
DatatypeConstants.FIELD_UNDEFINED);
request.setCurrentDt(xmlDate);
Object[] objs = client.invoke("xxxxxxxxxxxxx", request);
System.out.println(objs[0].toString());
} catch (Exception e) {
// TODO: handle exception
} 展开
展开全部
CXF调用
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import service.ICalculateService;
public class ClientTest {
public static void main(String[] args) {
// 创建webservice服务工厂
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// 加入一个接收响应日志的拦截器
factory.getInInterceptors().add(new LoggingInInterceptor());
// 加入一个返回响应日志的拦截器
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(ICalculateService.class);
factory.setAddress("http://localhost:6070/axis2/services/axis2Service?wsdl");
// 根据设置创建一个服务器
ICalculateService client = (ICalculateService) factory.create();
double reply = client.addNum(50, 30);
System.out.println(reply);
}
}
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import service.ICalculateService;
public class ClientTest {
public static void main(String[] args) {
// 创建webservice服务工厂
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// 加入一个接收响应日志的拦截器
factory.getInInterceptors().add(new LoggingInInterceptor());
// 加入一个返回响应日志的拦截器
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(ICalculateService.class);
factory.setAddress("http://localhost:6070/axis2/services/axis2Service?wsdl");
// 根据设置创建一个服务器
ICalculateService client = (ICalculateService) factory.create();
double reply = client.addNum(50, 30);
System.out.println(reply);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询