夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          webservice客戶端訪問服務的幾種方式
          1.最簡的一種
              根據對方提供的wsdl生成本地java類,訪問webservice就跟調用本地類沒有什么區(qū)別了.
          2.使用xfire的其中的一種調用方式,代碼如下:  
          import java.net.MalformedURLException;
          import java.net.URL;

          import org.codehaus.xfire.client.Client;





          public class Test
          {
              
          public void test() throws MalformedURLException, Exception
              
          {
                  Client client 
          = new Client(new URL("http://58.58.33.33/sqtwebservice/UserManage.asmx?wsdl"));
                  Object[] resultXMLObjs 
          = client.invoke("GetCurfee"new Object[] {"huy88888""123456" });
                  System.out.println(resultXMLObjs[
          0]);
              }

              
              
          public static void main(String[] args) throws MalformedURLException, Exception
              
          {
                  Test test 
          = new Test();
                  test.test();
              }

          }

          3.使用axis的其中一種調用方式:
          import java.math.BigDecimal;
          import java.net.MalformedURLException;
          import java.rmi.RemoteException;

          import javax.xml.namespace.QName;
          import javax.xml.rpc.ParameterMode;
          import javax.xml.rpc.ServiceException;

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

          /**
           * <ul>
           * <li>Title:[ProviderJiangXiTelecom]</li>
           * <li>Description: [江西電信-webservice]</li>
           * <li>Copyright 2009 Upengs Co., Ltd.</li>
           * <li>All right reserved.</li>
           * <li>Created by [Huyvanpull] [2011-1-7]</li>
           * <li>Midified by [modifier] [modified time]</li>
           * </ul>
           * 
           * 
          @version 1.0
           
          */

          public class ProviderJiangXiTelecom 
          {
              
          public void Webservice1()
              
          {
                  
          try
                  
          {
                      Service service 
          = new Service();
                      Call call 
          = (Call) service.createCall();
                      call.setTargetEndpointAddress(
          new java.net.URL("http://58.58.33.33/sqtwebservice/UserManage.asmx"));
                      call.setOperationName(
          new QName("http://tempuri.org/""GetCurfee"));
                      call.addParameter(
          "uname", XMLType.XSD_STRING, ParameterMode.IN);
                      call.addParameter(
          "pass", XMLType.XSD_STRING, ParameterMode.IN);
                      call.setUseSOAPAction(
          true);
                      call.setSOAPActionURI(
          "http://tempuri.org/GetCurfee");
                      call.setReturnType(XMLType.XSD_DECIMAL);
                      
                      BigDecimal result 
          = (BigDecimal) call.invoke(new Object[] "huy88888","123456" });
                      System.out.println(result.doubleValue());
                  }

                  
          catch (ServiceException e)
                  
          {
                      e.printStackTrace();
                  }

                  
          catch (RemoteException e)
                  
          {
                      e.printStackTrace();
                  }

                  
          catch (MalformedURLException e)
                  
          {
                      e.printStackTrace();
                  }

              }

              
          public static void main(String[] args)
              
          {
                  ProviderJiangXiTelecom providerJiangXiTelecom 
          = new ProviderJiangXiTelecom();
                  providerJiangXiTelecom.Webservice1();
              }

              
             
          }
          posted on 2011-01-07 12:55 HUIKK 閱讀(451) 評論(0)  編輯  收藏 所屬分類: webservice
          主站蜘蛛池模板: 板桥市| 龙里县| 泰宁县| 福贡县| 太谷县| 陈巴尔虎旗| 孝义市| 镇原县| 南汇区| 乐东| 都匀市| 石屏县| 吕梁市| 临汾市| 保山市| 镇康县| 盐山县| 竹溪县| 内黄县| 紫金县| 鲁山县| 连云港市| 太和县| 大城县| 手机| 阳山县| 怀安县| 和静县| 胶州市| 岱山县| 沈阳市| 荔波县| 莫力| 老河口市| 博乐市| 德令哈市| 巴彦县| 鄂州市| 樟树市| 马鞍山市| 若尔盖县|