一路拾遗
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 胖胖泡泡 阅读(6012) 评论(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
还是不行 老大!
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: