夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          webservice客戶端訪問服務的幾種方式
          1.最簡的一種
              根據對方提供的wsdl生成本地java類,訪問webservice就跟調用本地類沒有什么區別了.
          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
          主站蜘蛛池模板: 西畴县| 德州市| 上栗县| 曲水县| 澄江县| 竹溪县| 抚顺市| 青川县| 娱乐| 沾化县| 蓬溪县| 正宁县| 东至县| 池州市| 武夷山市| 南平市| 林甸县| 宣化县| 金昌市| 潼南县| 恩平市| 大余县| 客服| 萨迦县| 密山市| 青河县| 富源县| 西乌珠穆沁旗| 当雄县| 苏尼特左旗| 正蓝旗| 大埔区| 无棣县| 子洲县| 霍林郭勒市| 靖西县| 察雅县| 宜君县| 昌宁县| 会泽县| 库尔勒市|