您的位置:首页 > 编程语言 > Java开发

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: