posts - 495,comments - 227,trackbacks - 0
          原文地址:http://www.javaeye.com/topic/151541
          在原文基礎(chǔ)上加了點注釋 呵呵。

          所需jar包:
          saaj.jar
          wsdl4j-1.5.1.jar
          commons-discovery-0.2.jar
          commons-logging-1.0.4.jar
          jaxrpc.jar
          axis.jar

          這些jar包都在axis項目下,
          axis下載地址:http://ws.apache.org/axis/

          java代碼:
          // 需導(dǎo)入的類
          import javax.xml.namespace.QName;
          import org.apache.axis.client.Call;
          import org.apache.axis.client.Service;
          import org.apache.axis.encoding.XMLType;

          //              .net webService 地址
                  String url="http://localhost:1246/WebSite3/Service.asmx";  
          //              .net webService 命名空間
                  String namespace = "http://tempuri.org/";  
          //              .net webService 需調(diào)用的方法
                  String methodName = "HelloWorld";  
                  String soapActionURI = "http://tempuri.org/HelloWorld";  
                  Service service = new Service();
                  
                  Call call = (Call) service.createCall();

                  call.setTargetEndpointAddress(new java.net.URL(url));  
                  call.setUseSOAPAction(true);  
          //        這個地方?jīng)]設(shè)對就會出現(xiàn)Server was unable to read request的錯誤  
                  call.setSOAPActionURI(soapActionURI);  
          //              設(shè)置要調(diào)用的.net webService方法
                  call.setOperationName(new QName(namespace, methodName));  
          //              設(shè)置該方法的參數(shù),temp為.net webService中的參數(shù)名稱
                  call.addParameter( new QName(namespace,"temp"),  
                          org.apache.axis.encoding.XMLType.XSD_STRING,   
                          javax.xml.rpc.ParameterMode.IN);  
          //              設(shè)置該方法的返回值
                  call.setReturnType(XMLType.XSD_STRING);
          //              call.invoke(new Object[] { "kusix" });  中"kusix"為傳入?yún)?shù)值
                  String ret = (String) call.invoke(new Object[] { "kusix" });  
                  System.out.println("返回結(jié)果---> " + ret);  


          .net 代碼
          using System;
          using System.Web;
          using System.Web.Services;
          using System.Web.Services.Protocols;

          [WebService(Namespace = "http://tempuri.org/")]
          [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
          public class Service : System.Web.Services.WebService
          {
              public Service () {

                  //如果使用設(shè)計的組件,請取消注釋以下行
                  //InitializeComponent();
              }

              [WebMethod]
              public string HelloWorld(String temp) {
                  return temp+" add by .net";
              }
              
          }


          posted on 2010-05-11 11:41 SIMONE 閱讀(7657) 評論(2)  編輯  收藏 所屬分類: AXISJAVA

          FeedBack:
          # re: java通過axis訪問.net webService 簡單例子
          2011-07-22 09:30 | pengnan1111
          感謝這位大哥提供了寶貴的資料!  回復(fù)  更多評論
            
          # re: java通過axis訪問.net webService 簡單例子
          2014-10-27 11:56 | 路人甲
          為何kusix沒打印出來?  回復(fù)  更多評論
            
          主站蜘蛛池模板: 肃南| 苏尼特左旗| 杨浦区| 铜川市| 兰州市| 蕲春县| 康平县| 孟州市| 璧山县| 辛集市| 成安县| 常熟市| 屏南县| 金坛市| 西丰县| 收藏| 两当县| 江川县| 遂宁市| 柳江县| 象山县| 平遥县| 楚雄市| 云和县| 祁连县| 富阳市| 宁强县| 山阴县| 抚州市| 剑川县| 赤峰市| 湘乡市| 筠连县| 沙田区| 平遥县| 栾城县| 凌源市| 孝义市| 巴林右旗| 建昌县| 商都县|