spring cxf webservice
2012-07-20 09:13
363 查看
调用webservice 的两种方法
public static void main(String[] args) {
//不用wsdl生成java文件
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setAddress("http://localhost:7001/UIP/service/CxfTest");//spring-cxf.xml中的address
factory.setServiceClass(CxfTest.class);
CxfTest service = (CxfTest)factory.create();
User user=new User();
user.setAge("32");
user.setName("afds");
System.out.println(service.print(user));
//应用wsdl生成本地文件,推荐使用
CxfTestService service=new CxfTestService();
CxfTest cxfTest=service.getCxfTestPort();
User user=new User();
user.setAge("10234");
user.setName("adf324");
System.out.println(cxfTest.print(user));
}
wsdl文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="CxfTestService" targetNamespace="http://util.service/" xmlns:tns="http://util.service/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://util.service/" elementFormDefault="unqualified" targetNamespace="http://util.service/"
version="1.0">
<xs:element name="print" type="tns:print"/>
<xs:element name="printResponse" type="tns:printResponse"/>
<xs:complexType name="print">
<xs:sequence>
<xs:element minOccurs="0" name="user" type="tns:User"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="User">//复杂类型参数
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>//name属性
<xs:element minOccurs="0" name="age" type="xs:string"/>//age属性
</xs:sequence>
</xs:complexType>
<xs:complexType name="printResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="printResponse">
<wsdl:part name="parameters" element="tns:printResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="print">
<wsdl:part name="parameters" element="tns:print">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="CxfTest">//接口名字
<wsdl:operation name="print">//方法
<wsdl:input name="print" message="tns:print">
</wsdl:input>
<wsdl:output name="printResponse" message="tns:printResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CxfTestServiceSoapBinding" type="tns:CxfTest">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="print">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="print">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="printResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CxfTestService">
<wsdl:port name="CxfTestPort" binding="tns:CxfTestServiceSoapBinding">
<soap:address location="http://localhost:7001/UIP/service/CxfTest"/>//服务地址
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
public static void main(String[] args) {
//不用wsdl生成java文件
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setAddress("http://localhost:7001/UIP/service/CxfTest");//spring-cxf.xml中的address
factory.setServiceClass(CxfTest.class);
CxfTest service = (CxfTest)factory.create();
User user=new User();
user.setAge("32");
user.setName("afds");
System.out.println(service.print(user));
//应用wsdl生成本地文件,推荐使用
CxfTestService service=new CxfTestService();
CxfTest cxfTest=service.getCxfTestPort();
User user=new User();
user.setAge("10234");
user.setName("adf324");
System.out.println(cxfTest.print(user));
}
wsdl文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="CxfTestService" targetNamespace="http://util.service/" xmlns:tns="http://util.service/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://util.service/" elementFormDefault="unqualified" targetNamespace="http://util.service/"
version="1.0">
<xs:element name="print" type="tns:print"/>
<xs:element name="printResponse" type="tns:printResponse"/>
<xs:complexType name="print">
<xs:sequence>
<xs:element minOccurs="0" name="user" type="tns:User"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="User">//复杂类型参数
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>//name属性
<xs:element minOccurs="0" name="age" type="xs:string"/>//age属性
</xs:sequence>
</xs:complexType>
<xs:complexType name="printResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="printResponse">
<wsdl:part name="parameters" element="tns:printResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="print">
<wsdl:part name="parameters" element="tns:print">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="CxfTest">//接口名字
<wsdl:operation name="print">//方法
<wsdl:input name="print" message="tns:print">
</wsdl:input>
<wsdl:output name="printResponse" message="tns:printResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CxfTestServiceSoapBinding" type="tns:CxfTest">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="print">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="print">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="printResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CxfTestService">
<wsdl:port name="CxfTestPort" binding="tns:CxfTestServiceSoapBinding">
<soap:address location="http://localhost:7001/UIP/service/CxfTest"/>//服务地址
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
相关文章推荐
- java WebService CXF Spring 自定义拦截器 附实例源码
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF+WS-Security+Spring WebService服务器端+客户端及注意问题
- CXF WebService整合Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- CXF+SpringBoot webservice
- cxf集成到spring中发布restful webservice
- CXF WebService整合Spring
- 使用CXF与Spring集成实现RESTFul WebService
- Spring 集成CXF框架发布Webservice服务 和 使用jdk生成Webservice clinet
- CXF WebService整合Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- cxf 3.2+webservice+spring 4.2发布Rest WebService
- Cxf/webservice/spring编写应用程序接口的步骤
- CXF WebService整合Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- Eclipse安装CXF插件开发java web service 集成Spring