首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

如何用cxf客户端调用xfire服务端

2012-03-23 
怎么用cxf客户端调用xfire服务端xfrie生成的wsdl如下XML code?xml version1.0 encodingUTF-8 ? -

怎么用cxf客户端调用xfire服务端
xfrie生成的wsdl如下

XML code
<?xml version="1.0" encoding="UTF-8" ?> - <wsdl:definitions targetNamespace="http://webService.beans.com" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://webService.beans.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">- <wsdl:types>- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://webService.beans.com">- <xsd:element name="getReports">- <xsd:complexType>- <xsd:sequence>  <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" />   </xsd:sequence>  </xsd:complexType>  </xsd:element>- <xsd:element name="getReportsResponse">- <xsd:complexType>- <xsd:sequence>  <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" />   </xsd:sequence>  </xsd:complexType>  </xsd:element>- <xsd:element name="getReport">- <xsd:complexType>- <xsd:sequence>  <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" />   <xsd:element maxOccurs="1" minOccurs="1" name="in1" nillable="true" type="xsd:string" />   </xsd:sequence>  </xsd:complexType>  </xsd:element>- <xsd:element name="getReportResponse">- <xsd:complexType>- <xsd:sequence>  <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" />   </xsd:sequence>  </xsd:complexType>  </xsd:element>- <xsd:element name="getReportNames">- <xsd:complexType>- <xsd:sequence>  <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string" />   </xsd:sequence>  </xsd:complexType>  </xsd:element>- <xsd:element name="getReportNamesResponse">- <xsd:complexType>- <xsd:sequence>  <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string" />   </xsd:sequence>  </xsd:complexType>  </xsd:element>  </xsd:schema>  </wsdl:types>- <wsdl:message name="getReportNamesRequest">  <wsdl:part name="parameters" element="tns:getReportNames" />   </wsdl:message>- <wsdl:message name="getReportRequest">  <wsdl:part name="parameters" element="tns:getReport" />   </wsdl:message>- <wsdl:message name="getReportsRequest">  <wsdl:part name="parameters" element="tns:getReports" />   </wsdl:message>- <wsdl:message name="getReportNamesResponse">  <wsdl:part name="parameters" element="tns:getReportNamesResponse" />   </wsdl:message>- <wsdl:message name="getReportResponse">  <wsdl:part name="parameters" element="tns:getReportResponse" />   </wsdl:message>- <wsdl:message name="getReportsResponse">  <wsdl:part name="parameters" element="tns:getReportsResponse" />   </wsdl:message>- <wsdl:portType name="WSReportPortType">- <wsdl:operation name="getReports">  <wsdl:input name="getReportsRequest" message="tns:getReportsRequest" />   <wsdl:output name="getReportsResponse" message="tns:getReportsResponse" />   </wsdl:operation>- <wsdl:operation name="getReport">  <wsdl:input name="getReportRequest" message="tns:getReportRequest" />   <wsdl:output name="getReportResponse" message="tns:getReportResponse" />   </wsdl:operation>- <wsdl:operation name="getReportNames">  <wsdl:input name="getReportNamesRequest" message="tns:getReportNamesRequest" />   <wsdl:output name="getReportNamesResponse" message="tns:getReportNamesResponse" />   </wsdl:operation>  </wsdl:portType>- <wsdl:binding name="WSReportHttpBinding" type="tns:WSReportPortType">  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> - <wsdl:operation name="getReports">  <wsdlsoap:operation soapAction="" /> - <wsdl:input name="getReportsRequest">  <wsdlsoap:body use="literal" />   </wsdl:input>- <wsdl:output name="getReportsResponse">  <wsdlsoap:body use="literal" />   </wsdl:output>  </wsdl:operation>- <wsdl:operation name="getReport">  <wsdlsoap:operation soapAction="" /> - <wsdl:input name="getReportRequest">  <wsdlsoap:body use="literal" />   </wsdl:input>- <wsdl:output name="getReportResponse">  <wsdlsoap:body use="literal" />   </wsdl:output>  </wsdl:operation>- <wsdl:operation name="getReportNames">  <wsdlsoap:operation soapAction="" /> - <wsdl:input name="getReportNamesRequest">  <wsdlsoap:body use="literal" />   </wsdl:input>- <wsdl:output name="getReportNamesResponse">  <wsdlsoap:body use="literal" />   </wsdl:output>  </wsdl:operation>  </wsdl:binding>- <wsdl:service name="WSReport">- <wsdl:port name="WSReportHttpPort" binding="tns:WSReportHttpBinding">  <wsdlsoap:address location="http://data.dofcom.gov.cn/services/WSReport" />   </wsdl:port>  </wsdl:service>  </wsdl:definitions> 



我自己写的cxf方法如下:
Java code
import net.ilkj.soap.server.WSReport;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;public class CXFClientSample { public static void main(String[] args) throws Exception{     String dataString = "aaaa";  JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  factory.setAddress("http://xxx/services/WSReport");  factory.setServiceClass(WSReport.class);  WSReport service = (WSReport) factory.create();  String response = service.uploadDatas("xml", dataString);  System.out.println(response); }}


但是每次调用的时候都说是非法操作,到底该怎么调用啊,cxf怎么调用xfire客户端啊


[解决办法]
1、cfx调用webservice时需要加载
cxf-2.2.10.jar
jetty-6.1.21.jar
jetty-util-6.1.21.jar
servlet-2_5-api.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.5.jar
这些包。
服务端代码代码如下:
 Server impl=new Server();
JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean();
factoryBean.setAddress("http://ip地址/hello");
factoryBean.setServiceClass(HelloWorldServiceInf.class);
factoryBean.setServiceBean(impl);
factoryBean.getInInterceptors().add(new LoggingInInterceptor());
factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
factoryBean.create();
客户端代码
JaxWsProxyFactoryBean factoryBean=new JaxWsProxyFactoryBean();
factoryBean.getInInterceptors().add(new LoggingInInterceptor());
factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
factoryBean.setServiceClass(HelloWorldServiceInf.class);
factoryBean.setAddress("http://***/hello");
HelloWorldServiceInf impl=(HelloWorldServiceInf) factoryBean.create();
System.out.println(impl.sayHello("hello"));

希望能帮上你

热点排行