CXF动态调用wsdl

public static Object[] invokeRemoteMethodByCache(String url, String operation, Object parameters) {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
// 创建客户端连接
Client client = factory.createClient(url);
Object[] res = null;
try {
if(parameters==null)  //无参
res = client.invoke(operation);
else
res = client.invoke(operation, parameters);
}catch(Exception e) {
e.printStackTrace();
}
return res;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println("web service start");
// 远程webService的URL
        String hostUrl = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
        hostUrl = "http://localhost:8083/spring-cxf-ws/ws/v/1/teamService?wsdl";
        String methodName = "deletePlayer";
//        methodName = "getTeam";   //无参
        
        try{ 
        int queryTestData = 1;
        Object[] parameters= new Object[] {queryTestData};
       
        Object b = invokeRemoteMethodByCache( hostUrl, methodName, parameters[0] )[0];
//        Object b = invokeRemoteMethodByCache( hostUrl, methodName, null )[0];  //无参
        System.out.println(b);
       
        }catch(Exception e){e.printStackTrace();}
          
}

wsdl文件内容----------------------------------------

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.cxf.jaxws.demo.danielme.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="TeamServiceImplService" targetNamespace="http://ws.cxf.jaxws.demo.danielme.com/">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:types>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.cxf.jaxws.demo.danielme.com/" elementFormDefault="unqualified" targetNamespace="http://ws.cxf.jaxws.demo.danielme.com/" version="1.0">
<xs:element name="deletePlayer" type="tns:deletePlayer"/>
<xs:element name="deletePlayerResponse" type="tns:deletePlayerResponse"/>
<xs:element name="getPlayers" type="tns:getPlayers"/>
<xs:element name="getPlayersResponse" type="tns:getPlayersResponse"/>
<xs:element name="getTeam" type="tns:getTeam"/>
<xs:element name="getTeamResponse" type="tns:getTeamResponse"/>
<xs:element name="updatePlayerByNumber" type="tns:updatePlayerByNumber"/>
<xs:element name="updatePlayerByNumberResponse" type="tns:updatePlayerByNumberResponse"/>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="deletePlayer">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element name="arg0" type="xs:int"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="deletePlayerResponse">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="getTeam">
<xs:sequence/>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="getTeamResponse">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:player"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="player">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element name="age" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
<xs:element name="number" type="xs:int"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="getPlayers">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="arg0" type="xs:int"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="getPlayersResponse">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:player"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="updatePlayerByNumber">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element name="arg0" type="xs:int"/>
<xs:element minOccurs="0" name="arg1" type="tns:player"/>
</xs:sequence>
</xs:complexType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:complexType name="updatePlayerByNumberResponse">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><xs:sequence>
<xs:element name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="getPlayers">
<wsdl:part element="tns:getPlayers" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="updatePlayerByNumberResponse">
<wsdl:part element="tns:updatePlayerByNumberResponse" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="updatePlayerByNumber">
<wsdl:part element="tns:updatePlayerByNumber" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="deletePlayer">
<wsdl:part element="tns:deletePlayer" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="getTeam">
<wsdl:part element="tns:getTeam" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="deletePlayerResponse">
<wsdl:part element="tns:deletePlayerResponse" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="getPlayersResponse">
<wsdl:part element="tns:getPlayersResponse" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:message name="getTeamResponse">
<wsdl:part element="tns:getTeamResponse" name="parameters"> </wsdl:part>
</wsdl:message>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:portType name="ITeamService">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="deletePlayer">
<wsdl:input message="tns:deletePlayer" name="deletePlayer"> </wsdl:input>
<wsdl:output message="tns:deletePlayerResponse" name="deletePlayerResponse"> </wsdl:output>
</wsdl:operation>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="getTeam">
<wsdl:input message="tns:getTeam" name="getTeam"> </wsdl:input>
<wsdl:output message="tns:getTeamResponse" name="getTeamResponse"> </wsdl:output>
</wsdl:operation>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="getPlayers">
<wsdl:input message="tns:getPlayers" name="getPlayers"> </wsdl:input>
<wsdl:output message="tns:getPlayersResponse" name="getPlayersResponse"> </wsdl:output>
</wsdl:operation>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="updatePlayerByNumber">
<wsdl:input message="tns:updatePlayerByNumber" name="updatePlayerByNumber"> </wsdl:input>
<wsdl:output message="tns:updatePlayerByNumberResponse" name="updatePlayerByNumberResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:binding name="TeamServiceImplServiceSoapBinding" type="tns:ITeamService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="deletePlayer">
<soap:operation soapAction="" style="document"/>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:input name="deletePlayer">
<soap:body use="literal"/>
</wsdl:input>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:output name="deletePlayerResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="getTeam">
<soap:operation soapAction="" style="document"/>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:input name="getTeam">
<soap:body use="literal"/>
</wsdl:input>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:output name="getTeamResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="getPlayers">
<soap:operation soapAction="" style="document"/>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:input name="getPlayers">
<soap:body use="literal"/>
</wsdl:input>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:output name="getPlayersResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:operation name="updatePlayerByNumber">
<soap:operation soapAction="" style="document"/>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:input name="updatePlayerByNumber">
<soap:body use="literal"/>
</wsdl:input>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:output name="updatePlayerByNumberResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:service name="TeamServiceImplService">
"); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; vertical-align: bottom; height: 10px;"><wsdl:port binding="tns:TeamServiceImplServiceSoapBinding" name="TeamServiceImplPort">
<soap:address location="http://localhost:8083/spring-cxf-ws/ws/v/1/teamService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值