我的漫漫程序之旅

          專注于JavaWeb開發(fā)
          隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
          數(shù)據(jù)加載中……

          我的第一個(gè)WebServices程序(HelloWorld)

          用MyEclipse創(chuàng)建一個(gè)WebService 工程.

          然后創(chuàng)建一個(gè)WebService程序:

          package com.web;


          public class HelloWorldImpl implements IHelloWorld {
              
              
          public String example(String message)
              
          {
                  
          return "Welcome you !! this is first web service program!!" + message;
              }

              
          }

          IHelloWorld:
          package com.web;
          //Generated by MyEclipse

          public interface IHelloWorld 
          {
              
              
          public String example(String message);
              
          }

          這里你可以通過
          http://localhost:6666/webserver01/services/HelloWorld?wsdl
          進(jìn)行訪問,localhost可以換成你對外公開的IP地址.

          當(dāng)然也可以通過測試程序訪問:
          package com.test;

          import org.codehaus.xfire.XFireFactory;
          import org.codehaus.xfire.client.XFireProxyFactory;
          import org.codehaus.xfire.service.Service;
          import org.codehaus.xfire.service.binding.ObjectServiceFactory;

          import com.web.IHelloWorld;

          public class HelloWorldClient
          {
              
          public static void main(String[] args)
              
          {
                  Service srvcModel 
          = new ObjectServiceFactory()
                          .create(IHelloWorld.
          class);
                  XFireProxyFactory factory 
          = new XFireProxyFactory(XFireFactory
                          .newInstance().getXFire());
                  String helloWorldURL 
          = "http://localhost:6666/webserver01/services/HelloWorld";
                  
          try
                  
          {
                      IHelloWorld srvc 
          = (IHelloWorld) factory.create(srvcModel,
                              helloWorldURL);
                      String result 
          = srvc.example("zdw");
                      System.out.println(result);
                  }
           catch (Exception e)
                  
          {
                      e.printStackTrace();
                  }

              }


          }

          詳細(xì)可以參看MyEclipse自帶的Help Contents.
          此示例源碼下載點(diǎn)此下載

          posted on 2008-01-09 08:20 々上善若水々 閱讀(981) 評論(0)  編輯  收藏 所屬分類: WebService

          主站蜘蛛池模板: 庄河市| 武邑县| 平罗县| 永宁县| 托克逊县| 阿合奇县| 汪清县| 郧西县| 特克斯县| 聂拉木县| 垫江县| 盐山县| 石河子市| 三原县| 霸州市| 沽源县| 武汉市| 宜良县| 正宁县| 霍州市| 鄂托克前旗| 荔浦县| 库尔勒市| 阆中市| 江北区| 东源县| 遂平县| 达尔| 托克逊县| 盐山县| 洞口县| 长乐市| 鸡泽县| 达尔| 安远县| 日喀则市| 岳池县| 永昌县| 福安市| 长垣县| 城固县|