使用apache CXF開發第一個Web服務

banq發表於2009-08-30
Tutorial to develop Contract First webservice using CXF

我們要使用apache CXF完成下面這個Web服務:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="EmpWorkHours" targetNamespace="http://ts.com/empwork"    xmlns:tns="http://ts.com/empwork"    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"    xmlns="http://schemas.xmlsoap.org/wsdl/"    xmlns:emp="http://ts.com/empwork/types"    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <schema targetNamespace="http://ts.com/empwork/types"   xmlns="http://www.w3.org/2001/XMLSchema"       xmlns:tns="http://ts.com/empwork/types"          elementFormDefault="qualified">
            <xsd:element name="EmpWorkHoursRequest" type="emp:EmpWorkHoursRequestType"/>
            <xsd:element name="EmpWorkHoursResponse" type="emp:EmpWorkHoursResultType"/>
            <xsd:complexType name="EmpWorkHoursRequestType">
                <xsd:sequence>
                    <xsd:element name="empid" type="xsd:string"/>
                    <xsd:element name="year" type="xsd:integer"/>
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="EmpWorkHoursResultType">
                <xsd:sequence>
                    <xsd:element name="empid" type="xsd:string"/>
                    <xsd:element name="year" type="xsd:integer"/>
                    <xsd:element name="name" type="xsd:string"/>
                    <xsd:element name="workhours" type="xsd:integer"/>
                </xsd:sequence>
            </xsd:complexType>
        </schema>
    </wsdl:types>
    <wsdl:message name="request">
        <wsdl:part element="emp:EmpWorkHoursRequest" name="in"/>
    </wsdl:message>
    <wsdl:message name="response">
        <wsdl:part element="emp:EmpWorkHoursResponse" name="out"/>
    </wsdl:message>
    <wsdl:portType name="EmpWorkHours">
        <wsdl:operation name="getWorkHours">
            <wsdl:input message="tns:request" name="workHoursRequest"/>
            <wsdl:output message="tns:response" name="workHoursResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="EmpWorkHours_SOAPBinding" type="tns:EmpWorkHours">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/
http"/>
        <wsdl:operation name="getWorkHours">
            <soap:operation SOApAction="" style="document"/>
            <wsdl:input name="workHoursRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="workHoursResponse">
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="SOAPService">
        <wsdl:port binding="tns:EmpWorkHours_SOAPBinding" name="EmpWorkHoursWS">
            <soap:address location="http://localhost:8090/cxfcontractfirstwebapp/services/
EmpWorkHoursWS"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
<p class="indent">

相關文章