XML WSDL
- WSDL ย่อมาจาก Web Services Description Language
- WSDL ใช้เพื่ออธิบายบริการเว็บ
- WSDL เขียนด้วย XML
- WSDL เป็นคำแนะนำของ W3C ตั้งแต่วันที่ 26 มิถุนายน 2550
เอกสาร WSDL
เอกสาร WSDL อธิบายบริการเว็บ ระบุตำแหน่งของบริการ และวิธีการของบริการ โดยใช้องค์ประกอบหลักเหล่านี้:
Element | Description |
---|---|
<types> | Defines the (XML Schema) data types used by the web service |
<message> | Defines the data elements for each operation |
<portType> | Describes the operations that can be performed and the messages involved. |
<binding> | Defines the protocol and data format for each port type |
โครงสร้างหลักของเอกสาร WSDL มีลักษณะดังนี้:
<definitions>
<types>
data type definitions........
</types>
<message>
definition of the data being communicated....
</message>
<portType>
set of operations......
</portType>
<binding>
protocol and data format specification....
</binding>
</definitions>
ตัวอย่าง WSDL
นี่เป็นเศษส่วนแบบง่ายของเอกสาร WSDL:
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
ในตัวอย่างนี้ องค์ประกอบ <portType>กำหนด "glossaryTerms" เป็นชื่อของพอร์ตและ "getTerm" เป็นชื่อของการดำเนินการ
การดำเนินการ "getTerm" มีข้อความป้อนเข้าชื่อ "getTermRequest" และข้อความส่งออกชื่อ "getTermResponse"
องค์ประกอบ<ข้อความ>กำหนดส่วนต่างๆของแต่ละข้อความและประเภทข้อมูลที่เกี่ยวข้อง
<portType> องค์ประกอบ
องค์ประกอบ <portType> กำหนดบริการเว็บการดำเนินการที่สามารถทำได้ และข้อความที่เกี่ยวข้อง
ประเภทการตอบกลับคำขอเป็นประเภทการดำเนินการที่พบบ่อยที่สุด แต่ WSDL กำหนดสี่ประเภท:
Type | Definition |
---|---|
One-way | The operation can receive a message but will not return a response |
Request-response | The operation can receive a request and will return a response |
Solicit-response | The operation can send a request and will wait for a response |
Notification | The operation can send a message but will not wait for a response |
การดำเนินงานทางเดียว WSDL
ตัวอย่างการดำเนินการทางเดียว:
<message name="newTermValues">
<part name="term" type="xs:string"/>
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="setTerm">
<input name="newTerm" message="newTermValues"/>
</operation>
</portType >
ในตัวอย่างข้างต้น portType "glossaryTerms" กำหนดการดำเนินการทางเดียวที่เรียกว่า "setTerm"
การดำเนินการ "setTerm" อนุญาตให้ป้อนข้อความคำศัพท์ใหม่โดยใช้ข้อความ "newTermValues" ที่มีพารามิเตอร์ป้อนเข้า "term" และ "value" อย่างไรก็ตาม ไม่มีการกำหนดเอาต์พุตสำหรับการดำเนินการ
การดำเนินการตอบสนองคำขอ WSDL
ตัวอย่างการดำเนินการตอบรับคำขอ:
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
ในตัวอย่างข้างต้น portType "glossaryTerms" กำหนดการดำเนินการตอบสนองคำขอที่เรียกว่า "getTerm"
การดำเนินการ "getTerm" ต้องการข้อความป้อนเข้าที่เรียกว่า "getTermRequest" โดยมีพารามิเตอร์ชื่อ "term" และจะส่งคืนข้อความเอาต์พุตที่เรียกว่า "getTermResponse" พร้อมพารามิเตอร์ที่เรียกว่า "value"
WSDL ผูกกับ SOAP
การเชื่อมโยง WSDL กำหนดรูปแบบข้อความและรายละเอียดโปรโตคอลสำหรับบริการเว็บ
ตัวอย่างการดำเนินการตอบรับคำขอ:
<message name="getTermRequest">
<part name="term" type="xs:string"/>
</message>
<message name="getTermResponse">
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="getTerm">
<input message="getTermRequest"/>
<output message="getTermResponse"/>
</operation>
</portType>
<binding type="glossaryTerms" name="b1">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation>
<soap:operation
soapAction="http://example.com/getTerm"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>
</binding>
องค์ประกอบ การผูกมีสองแอตทริบิวต์ - ชื่อและประเภท
แอตทริบิวต์ชื่อ (คุณสามารถใช้ชื่อใดก็ได้ที่คุณต้องการ) กำหนดชื่อของการเชื่อมโยง และแอตทริบิวต์ประเภทจะชี้ไปที่พอร์ตสำหรับการผูก ในกรณีนี้คือพอร์ต "คำศัพท์"
องค์ประกอบsoap:bindingมีสองคุณลักษณะ - สไตล์และการขนส่ง
แอตทริบิวต์ style อาจเป็น "rpc" หรือ "document" ในกรณีนี้เราใช้เอกสาร แอตทริบิวต์การขนส่งกำหนดโปรโตคอล SOAP ที่จะใช้ ในกรณีนี้เราใช้ HTTP
อิลิเมนต์ การดำเนินการกำหนดแต่ละการดำเนินการที่ portType เปิดเผย
สำหรับแต่ละการดำเนินการ ต้องกำหนดการดำเนินการ SOAP ที่สอดคล้องกัน คุณต้องระบุวิธีการเข้ารหัสอินพุตและเอาต์พุตด้วย ในกรณีนี้เราใช้ "ตัวอักษร"