<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    當柳上原的風吹向天際的時候...

    真正的快樂來源于創造

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
    WebService的原始API直接書寫在代碼中有諸多不便,如果我們把其調用過程歸納成一個類,再用Spring把URI和方法名注入到實例中去,這樣就好些了。

    歸納出來的WebService調用類:
    package com.heyang;

    import java.net.MalformedURLException;
    import java.rmi.RemoteException;

    import javax.xml.rpc.ServiceException;

    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;

    /**
     * WebService統一調用類
     * 
    @author: 何楊(heyang78@gmail.com)
     * @date: 2009-10-10-下午11:47:56
     
    */
    public class WebService{
        
    private String endpoint;
        
        
    private String operationName;
        
        
    /**
         * 取得WebService調用的結果
         * 
    @param args
         * 
    @return
         * 
    @throws ServiceException
         * 
    @throws MalformedURLException
         * 
    @throws RemoteException
         
    */
        
    public Object getCallResult(Object[] args)throws ServiceException, MalformedURLException, RemoteException{
            
    // 創建 Service實例
            Service service = new Service();
            
            
    // 通過Service實例創建Call的實例
            Call call = (Call) service.createCall();
            
            
    // 將Web Service的服務路徑加入到call實例之中.
            call.setTargetEndpointAddress(new java.net.URL(endpoint));// 為Call設置服務的位置
            
            
    // 調用Web Service的方法
            call.setOperationName(operationName);
            
            
    // 調用Web Service,傳入參數
            return call.invoke(args);
        }

        
    public String getEndpoint() {
            
    return endpoint;
        }

        
    public void setEndpoint(String endpoint) {
            
    this.endpoint = endpoint;
        }

        
    public String getOperationName() {
            
    return operationName;
        }

        
    public void setOperationName(String operationName) {
            
    this.operationName = operationName;
        }
    }

    再在上下文中配置三個bean,這樣WebService的相關信息就變成可配置方式了:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
        
    <bean id="method_isExist" class="com.heyang.WebService" >    
            
    <property name="endpoint">
                
    <value>http://localhost:8080/UserLoginService/services/login</value>
            
    </property>
            
    <property name="operationName">
                
    <value>isExist</value>
            
    </property>
        
    </bean>
        
        
    <bean id="method_getUserRole" class="com.heyang.WebService" >    
            
    <property name="endpoint">
                
    <value>http://localhost:8080/UserLoginService/services/login</value>
            
    </property>
            
    <property name="operationName">
                
    <value>getUserRole</value>
            
    </property>
        
    </bean>
        
        
    <bean id="method_getUserTrade" class="com.heyang.WebService" >    
            
    <property name="endpoint">
                
    <value>http://localhost:8080/UserLoginService/services/login</value>
            
    </property>
            
    <property name="operationName">
                
    <value>getUserTrade</value>
            
    </property>
        
    </bean>
     
    </beans>

    調用因此也變得相對簡單:
    package com.heyang;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;

    /**
     * 使用Spring的簡約式調用WebService
     * 
    @author: 何楊(heyang78@gmail.com)
     * @date: 2009-10-10-下午11:40:49
     
    */
    public class SpringTest{
        
    public static void main(String[] args){
            
    try{
                ApplicationContext appContext 
    = new ClassPathXmlApplicationContext("bean.xml");
                Object[] params
    =new Object[] { "MT001","123" };
                
                WebService ws1
    =(WebService)appContext.getBean("method_isExist");
                WebService ws2
    =(WebService)appContext.getBean("method_getUserRole");
                WebService ws3
    =(WebService)appContext.getBean("method_getUserTrade");
                
                System.out.println(ws1.getCallResult(params));
                System.out.println(ws2.getCallResult(params));
                System.out.println(ws3.getCallResult(params));
            }
            
    catch(Exception ex){
                ex.printStackTrace();
            }
        }
    }

    代碼下載(jar請從前面的程序里找,WebService即用上一篇文章中的UserLoginService):
    http://m.tkk7.com/Files/heyang/UserLoginServiceTest20091011082831.rar
    posted on 2009-10-11 00:10 何楊 閱讀(4265) 評論(1)  編輯  收藏

    Feedback

    # re: 使用Spring簡化對WebService的調用過程[未登錄] 2016-05-25 14:50 aa
    1111  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 在线观看亚洲网站| 校园亚洲春色另类小说合集| 中国一级毛片免费看视频| 日本19禁啪啪无遮挡免费动图| 亚洲人成无码网站在线观看| 黄瓜视频高清在线看免费下载| 亚洲人成毛片线播放| 美女视频黄的全免费视频| 国产精品亚洲四区在线观看| 一二三四在线观看免费高清中文在线观看| 亚洲成无码人在线观看| 无码国产精品一区二区免费式影视| 亚洲人成片在线观看| 日韩免费观看一级毛片看看| 免费无码婬片aaa直播表情| 亚洲日韩在线观看| 国产午夜无码精品免费看| 亚洲AV成人无码久久精品老人| 四虎影视成人永久免费观看视频| 亚洲精品视频在线播放| 国产三级在线观看免费| 猫咪免费人成在线网站| 亚洲色欲久久久综合网东京热| 暖暖免费日本在线中文| 亚洲中文字幕在线无码一区二区| 女人张腿给男人桶视频免费版| 国产亚洲午夜精品| 亚洲va久久久噜噜噜久久| 成人午夜免费福利视频| 亚洲成熟丰满熟妇高潮XXXXX| 国产午夜亚洲精品国产成人小说| 久久青草国产免费观看| 久久狠狠爱亚洲综合影院| 亚洲精品乱码久久久久久不卡| 久久aa毛片免费播放嗯啊| 亚洲中文字幕无码中文| 久久精品国产亚洲AV不卡| 我们的2018在线观看免费高清| 午夜在线亚洲男人午在线| 内射干少妇亚洲69XXX| 免费人成年激情视频在线观看|