2
關鍵是使用SOAP將一個人添加到電話簿(稱爲addPerson())的簡單白頁Web服務。如果電話 中已經有一位姓和名相同的人,則應該返回錯誤消息。從xml模式創建java類
我做了以下的WSDL文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="whitepages" targetNamespace="http://whitepages.ws"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://whitepages.ws" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema targetNamespace="http://whitepages.ws" xmlns:tns="http://whitepages.ws">
<xsd:complexType name="personType">
<xsd:sequence>
<xsd:element name="address" type="tns:addressType"></xsd:element>
</xsd:sequence>
<xsd:attribute name="firstName" type="xsd:string"/>
<xsd:attribute name="lastName" type="xsd:string"/>
<xsd:attribute name="phone" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="addressType">
<xsd:sequence>
<xsd:element name="street">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="postcode">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="city">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="person" type="tns:personType"></xsd:element>
<xsd:element name="response" type="xsd:string"></xsd:element>
<xsd:complexType name="faultType">
<xsd:sequence>
<xsd:element name="errorMessage" type="xsd:string"></xsd:element>
<xsd:element name="person" type="tns:personType"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="fault" type="tns:faultType"></xsd:element>
</xsd:schema>
</types>
<message name="whitepagesOperationRequest">
<part name="person" element="tns:person"/>
</message>
<message name="whitepagesOperationResponse">
<part name="response" element="tns:response"/>
</message>
<message name="WPFault">
<part name="errorMessage" type="xsd:string"/>
<part name="person" element="tns:person"/>
</message>
<portType name="whitepages">
<operation name="addPerson">
<input name="input1" message="tns:whitepagesOperationRequest"/>
<output name="output1" message="tns:whitepagesOperationResponse"/>
<fault name="fault1" message="tns:WPFault"/>
</operation>
</portType>
<binding name="whitepagesBinding" type="tns:whitepages">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="addPerson">
<soap:operation style="document"/>
<input name="input1">
<soap:body use="literal"/>
</input>
<output name="output1">
<soap:body use="literal"/>
</output>
<fault name="fault1">
<soap:fault name="fault1" use="literal"/>
</fault>
</operation>
</binding>
<service name="whitepagesService">
<port name="whitepagesBindingPort" binding="tns:whitepagesBinding">
<soap:address location="http://localhost:${HttpDefaultPort}/service"/>
</port>
</service>
</definitions>
我驗證了XML,現在我需要爲架構的Java類(兩個),但我不知道如何着手...任何建議或提示將非常感激..
在此先感謝
最佳點(或參考實現https://jaxb.java.net/) – Seismoid 2014-09-26 17:44:09