调用webservice例子代码

来源:互联网 发布:新浪手游助手mac 编辑:程序博客网 时间:2024/06/05 21:52

                                        调用webservice例子代码

 

 

 

平台:Nutz

 

 

后台调用:

 

    @At    @Ok("json")    public Object getPersonInfo(String idCard){                String result = "";try {result = getWebServiceResult("http://localhost:8080/sjsjzx/services/SjrkkService?wsdl", "getPersonInfo", idCard);} catch (Exception e) {e.printStackTrace();}                return result;    }/** * 调用webservice的方法. * @param url wsdl链接 * @param method 调用的接口 * @param idCard 传入的参数 * @return * @throws Exception */private String getWebServiceResult( String url, String method, String idCard) throws Exception{String rtnXml = null;try {String endpoint = url;Service service = new Service();Call call = (Call) service.createCall();call.setTargetEndpointAddress(new java.net.URL(endpoint));call.setOperationName(method);rtnXml = (String) call.invoke(new Object[]{idCard});} catch (Exception e) {e.printStackTrace();} return rtnXml;}


jsp测试:

 

//测试调用webservicefunction getPersonInfo(idCard){$.post("${ctx}/person/getPersonInfo?idCard="+idCard,{Action:"post"},function(data,textStatus){alert(data);},"json");}


 

 

1 0
原创粉丝点击