java調用(axis2)WebService傳遞物件類型參數(源碼)

來源:互聯網
上載者:User

標籤:type   des   com   remote   介面   public   rac   str   儲存   

溫馨提示:axis2 jar包喲


    public static String pubRemoteFuc() {
        
        String endpoint = "http://cnblogs.com/qgc/xxxx/Service?wsdl";
        String result = "error";
        Service service = new Service();
        Call call;


        //參數對象
        SearchInfoVo d=new SearchInfoVo();
        d.setName("李建");
        d.setCardNum("44xxxxx");
   
        
        Object[] object = new Object[1];
        object[0] = d;//Object是用來儲存方法的參數
        try {
            call = (Call) service.createCall();
            call.setTargetEndpointAddress(endpoint);// 遠程調用路徑
              QName qn = new QName("http://nciic.com.cn", "check" ); //介面的命名空間,請根據您的實際介面填寫,和方法名稱:<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:nci="http://nciic.com.cn" 

   
                call.setOperationName(qn);
                //設定參數的類型(這裡是實體物件“SearchInfoVo”)http://cnblogs.com/qgc
              call.registerTypeMapping(SearchInfoVo.class,qn,  
                        new BeanSerializerFactory(SearchInfoVo.class, qn),  
                        new BeanDeserializerFactory(SearchInfoVo.class, qn));  
              call.addParameter("arg0", qn, ParameterMode.IN );  //"arg0"不用改喲,我這裡只有一個參數,並且參數是一個實體物件  http://cnblogs.com/qgc
//            // 設定參數名:http://cnblogs.com/qgc
//            call.addParameter("name", // 參數名
//                    XMLType.XSD_STRING,// 參數類型:String
//                    ParameterMode.IN);// 參數模式:‘IN‘ or ‘OUT‘
/*            // 設定參數名:http://cnblogs.com/qgc
            call.addParameter("cardNum", // 參數名
                    XMLType.XSD_STRING,// 參數類型:String
                    ParameterMode.IN);// 參數模式:‘IN‘ or ‘OUT‘
            // 設定參數名:http://cnblogs.com/qgc
            call.addParameter("citizenId", // 參數名
                    XMLType.XSD_STRING,// 參數類型:String
                    ParameterMode.IN);// 參數模式:‘IN‘ or ‘OUT‘
*/            // 設定傳回值類型:
            //call.setReturnType(XMLType.XSD_STRING);// 傳回值類型:String
            call.setReturnType(XMLType.XSD_STRING);// 傳回值類型:String

            result = (String) call.invoke(object);// 遠程調用
            System.out.println(result);
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return result;
    }

 

public static void main(String[] args) throws Exception {

pubRemoteFuc();//調用

}

java調用(axis2)WebService傳遞物件類型參數(源碼)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.