Send Binary With Web Services in PHP (2009-06-26)

อาจจะมีบางคนที่ต้องการทำ web service ซึ่งมันเป็น message oriented remote procedure call (แอบยืมภาษาเทพจาก narisa มาใช้ หุหุ)
แล้วเราจะส่งไฟล์ที่เป็น Binary ได้อย่างไร เอาหล่ะซิ่ มันมีทางออกครับ
อ่ะแล้วทำไงหล่ะ ก็ใน php มันมี function base64 (ซึ่งภาษาอื่นก็มี) เราก็แปลงไฟล์ binary ต่างๆ เหล่านั้นโดยเข้ารหัสมันด้วย
ิbase64encode มันก็จะกลายเป็นชุดอักขระชุดนึง ก็จะสามารถส่งไป webservice ได้
ส่วน application ที่เรียกใช้ webservice เมื่อได้รับก้ใช้ function base64 decode กลับ โอ้ ง่ายไหมหนอน้องเอ๋ย
โดยมี WSDl ที่มี xml schema คล้ายนี้
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:int"/>
<xs:element name="photo" type="xs:base64Binary"/>
</xs:sequence>
</xs:complexType>
</xs:element> element photo เราก็เข้ารหัสด้วย base64 ซะ
|