一路拾遺
          Collect By Finding All The Way ......
          posts - 81,comments - 41,trackbacks - 0
          今天發現自己陷入了一個誤區。前面做的調用OWL-S服務時是使用描述文件鏈接進行調用的,所以對于遠程的WSDL文件也一直用描述文件鏈接調用,今天和師兄討論了一下,恍然大悟!WSDL和OWL-S不同,它調用時要使用 targetNamespace 來作為 TargetEndpointAddress 。而WSDL文件中其他的內容的作用是為了說明該服務有哪些接口、那些參數,以便調用的時候能夠正確的進行參數的設置。OWL-S在調用的時候能夠自動地獲取操作的名稱和參數類型,無需調用時指定;而WSDL文件則需要在調用之前指定操作和參數的信息(怪不得網上的調用的例子在調用之前都要首先對WSDL進行解析),否則會發生調用錯誤。也許這就是由于WSDL文件中可以包含多個操作,而OWL-S文件中只有一個操作的原因。下面同樣是對 DictionaryService 進行調用的實例:
          一、DictionaryService.wsdl 文件內容
          <?xml version="1.0" encoding="UTF-8"?>
          <wsdl:definitions targetNamespace="http://www.mindswap.org/axis/services/DictionaryService" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://www.mindswap.org/axis/services/DictionaryService" xmlns:intf="http://www.mindswap.org/axis/services/DictionaryService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <!--WSDL created by Apache Axis version: 1.2.1
          Built on Jun 14, 2005 (09:15:57 EDT)
          -->

             
          <wsdl:message name="getMeaningRequest">

                
          <wsdl:part name="in0" type="xsd:string"/>

             
          </wsdl:message>

             
          <wsdl:message name="getMeaningResponse">

                
          <wsdl:part name="getMeaningReturn" type="xsd:string"/>

             
          </wsdl:message>

             
          <wsdl:portType name="DictionaryService">

                
          <wsdl:operation name="getMeaning" parameterOrder="in0">

                   
          <wsdl:input message="impl:getMeaningRequest" name="getMeaningRequest"/>

                   
          <wsdl:output message="impl:getMeaningResponse" name="getMeaningResponse"/>

                
          </wsdl:operation>

             
          </wsdl:portType>

             
          <wsdl:binding name="DictionaryServiceSoapBinding" type="impl:DictionaryService">

                
          <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

                
          <wsdl:operation name="getMeaning">

                   
          <wsdlsoap:operation soapAction=""/>

                   
          <wsdl:input name="getMeaningRequest">

                      
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://services.mindswap.org" use="encoded"/>

                   
          </wsdl:input>

                   
          <wsdl:output name="getMeaningResponse">

                      
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.mindswap.org/axis/services/DictionaryService" use="encoded"/>

                   
          </wsdl:output>

                
          </wsdl:operation>

             
          </wsdl:binding>

             
          <wsdl:service name="DictionaryServiceService">

                
          <wsdl:port binding="impl:DictionaryServiceSoapBinding" name="DictionaryService">

                   
          <wsdlsoap:address location="http://www.mindswap.org/axis/services/DictionaryService"/>

                
          </wsdl:port>

             
          </wsdl:service>

          </wsdl:definitions>

          二、調用過程代碼
          package wsdl;

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

          public class CallService {

              
          public static void main(String[] args) {

                  
          try {
                                 
                      String endpoint 
          = "http://www.mindswap.org/axis/services/DictionaryService";
                      
          //調用過程
                      Service service = new Service();
                      
                      Call call 
          = (Call) service.createCall();
                      
                      call.setTargetEndpointAddress(
          new  java.net.URL(endpoint));
                      
                      call.setOperationName(
          "getMeaning");//WSDL里面描述的操作名稱
                      
                      call.addParameter(
          "getMeaningRequest", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);//操作的參數
                      
                      call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
          //設置返回類型  
                      
                      call.setUseSOAPAction( 
          true );
                      
                      
          //給方法傳遞參數,并且調用方法
                      String temp = "good";
                      Object[] obj 
          = new Object[]{temp};
                      String result 
          = (String)call.invoke(obj);
                      
                      System.out.println(
          "Result is : "+result);
                      }
           catch (Exception e) {
                          e.printStackTrace();
                      }

              }

          }


          posted on 2008-08-05 11:40 胖胖泡泡 閱讀(6045) 評論(5)  編輯  收藏

          FeedBack:
          # re: 使用AXIS調用WSDL描述的Web服務(續)
          2008-11-20 13:26 | yes1000y
          看了你兩篇文章,發現你在解決這個問題的時候,在調用WebService服務時傳的endpoint不一樣,是否是endpoint= "http://www.mindswap.org/axis/services/DictionaryService?wsdl";后面多了個(?wsdl)才會出現這個異常?是否把(?wsdl)去掉就可以調用接口提供的方法?
            回復  更多評論
            
          # re: 使用AXIS調用WSDL描述的Web服務(續)
          2008-12-04 10:33 | 胖胖泡泡
          @yes1000y
          不是的,調用wsdl文件的關鍵就在于Endpoint值的設置,應該為WSDL文件中的Targetnamespace值;而非WSDL文件本身的URL。  回復  更多評論
            
          # re: 使用AXIS調用WSDL描述的Web服務(續)
          2009-05-26 11:45 | wzg668
          果然是后面多了一個(?wsdl)
          害得我在google上翻來覆去。
          真是大海撈針啊終于找到了。
            回復  更多評論
            
          # re: 使用AXIS調用WSDL描述的Web服務(續)
          2010-04-01 15:17 | sjx
          @yes1000y
          WSDL文檔分為兩種,一種是服務接口文檔,一種是服務實現文檔,服務接口文檔有個targetNamespace屬性是用來對WSDL文檔進行定位的(這種定位不同于url定位),這樣服務實現文檔就可以通過targetNamespace來引用一個或多個服務接口文檔了  回復  更多評論
            
          # re: 使用AXIS調用WSDL描述的Web服務(續)[未登錄]
          2010-07-13 14:38 | test
          還是不行 老大!
            回復  更多評論
            

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


          網站導航:
           
          主站蜘蛛池模板: 洛川县| 石棉县| 聂荣县| 阳信县| 共和县| 玉门市| 安泽县| 珲春市| 池州市| 大洼县| 黄大仙区| 米泉市| 邵东县| 梁山县| 泉州市| 科尔| 襄樊市| 东台市| 兰坪| 东乡县| 清水县| 夏津县| 宜宾县| 巴里| 岑溪市| 辽宁省| 龙川县| 万山特区| 台州市| 修武县| 工布江达县| 望江县| 衡南县| 开远市| 麻江县| 景洪市| 来凤县| 三明市| 怀仁县| 嘉黎县| 虞城县|