有关java调用Service接口
2015-05-14 20:25
381 查看
webservice的调用,常用的大约有3种方式:
1、使用axis调用
2、使用xfire调用
3、使用cxf调用
本文先介绍axis调用
先上代码:
然后将XML文件解析出来,获取需要的参数值。
这里的写法模式基本上是固定的,最需要注意的就是传入的地址和参数的写法,否则很容易就报错了。
两种报错:
(1){http://xml.apache.org/axis/}HttpErrorCode:404
(404)Not Found
不是你的webservice没有发布成功,就是你的url输入错了,仔细去检查下
(2) faultDetail:
{http://xml.apache.org/axis/}stackTrace:服务器无法处理请求。 ---> ORA-00936: 缺失表达式
这种情况则是参数没有设置正确,导致传入参数是报错
推荐博客:http://www.tuicool.com/articles/6NjqIn
http://blog.csdn.net/quwei7515/article/details/17952085 http://zhidao.baidu.com/link?url=35bzoFNmQCM-AGt_m5F8-oC1EW3q-X2HborpRZ1zbwW36bpPbUGnblGQDUeIYA_5xwJE4LlEfWOkjG7VoyTq_Xlvi-lq8VMKjje8jR52K6W
1、使用axis调用
2、使用xfire调用
3、使用cxf调用
本文先介绍axis调用
先上代码:
package com.java; import java.net.MalformedURLException; import java.rmi.RemoteException; import org.apache.axis.client.Service; import org.apache.axis.client.Call; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; import javax.xml.rpc.ServiceException; public class WebServiceTest { public static void main(String[] args) throws MalformedURLException, ServiceException, RemoteException { //标识Web Service的具体路径 String endpoint="http://localhost/EMRToMobileService/EMRToMobileService.asmx?WSDL"; //发布的wsdl里的targetNamespace里的url String nameSpaceUri = "http://tempuri.org/"; Call call; Object res = ""; // 创建 Service实例 Service service = new Service(); try { // 通过Service实例创建Call的实例 call = (Call)service.createCall(); String strPatientID="415555"; String strEventNo="1"; //将Web Service的服务路径加入到call实例之中. call.setTargetEndpointAddress(new java.net.URL(endpoint)); //发布的方法名 call.setOperationName(new QName(nameSpaceUri,"GetEMRList")); //设置参数,主要要和net接口中的名称一致,类型尽量用String,注意QName中参数的设置 call.addParameter(new QName("http://tempuri.org/","strPatientID"), org.apache.axis.Constants.XSD_STRING,ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/","strEventNo"), org.apache.axis.Constants.XSD_STRING,ParameterMode.IN); call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); call.setUseSOAPAction(true); //这里注意有方法名,已经引用的地址。从net接口中找 ,注意地址的写法 call.setSOAPActionURI("http://tempuri.org/GetEMRList"); res =call.invoke(new Object[]{strPatientID,strEventNo}); //返回值String System.err.println("method:"+res); } catch (ServiceException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); }catch (Exception e) { e.printStackTrace(); } finally { } } }
然后将XML文件解析出来,获取需要的参数值。
这里的写法模式基本上是固定的,最需要注意的就是传入的地址和参数的写法,否则很容易就报错了。
两种报错:
(1){http://xml.apache.org/axis/}HttpErrorCode:404
(404)Not Found
不是你的webservice没有发布成功,就是你的url输入错了,仔细去检查下
(2) faultDetail:
{http://xml.apache.org/axis/}stackTrace:服务器无法处理请求。 ---> ORA-00936: 缺失表达式
这种情况则是参数没有设置正确,导致传入参数是报错
推荐博客:http://www.tuicool.com/articles/6NjqIn
http://blog.csdn.net/quwei7515/article/details/17952085 http://zhidao.baidu.com/link?url=35bzoFNmQCM-AGt_m5F8-oC1EW3q-X2HborpRZ1zbwW36bpPbUGnblGQDUeIYA_5xwJE4LlEfWOkjG7VoyTq_Xlvi-lq8VMKjje8jR52K6W
相关文章推荐
- java webservice调用.net接口
- Java WebService接口生成和调用 图文详解
- java webservice调用c#接口并传多个参数
- JAVA WebService接口调用
- Android(java)学习笔记229:服务(service)之绑定服务调用服务里面的方法 (采用接口隐藏代码内部实现)
- Java WebService接口生成和调用 图文详解
- Java WebService 简单实例 方式三(axis1接口调用方式)
- Java WebService 接口的简单生成和调用
- 简单的java webservice 接口 C#调用java webservice(crud)
- Java WebService 接口调用
- php调用java webservice接口
- SAP的RFC接口的发布与JAVA调用
- java代码调用webservice接口
- PHP5 在调用 JAVA WebService 时遇到的各种问题及解决方法(一)
- java实现跨系统接口调用简单
- PHP5 在调用 JAVA WebService 时遇到的各种问题及解决方法(二)
- java定时任务接口ScheduledExecutorService
- java接口调用——webservice就是一个RPC而已
- Java 调用底层接口的几种方法
- 使用java调用hadoop接口学习笔记