W3C(万维网联盟)制订的Web效劳标准是现代收集利用开辟的基本。控制W3C Web效劳,对开辟者来说至关重要。本文将具体介绍W3C Web效劳的基本不雅点、关键技巧,并供给实战教程,帮助读者轻松入门。
Web效劳是一种容许差别体系之间停止交互的软件效劳。它遵守W3C标准,经由过程互联网停止通信,实现数据的交换跟操纵。
SOAP是一种轻量级、简单的消息转达协定,用于在收集上交换构造化信息。
WSDL用于描述Web效劳的接口,包含效劳供给的操纵、数据范例跟通信协定。
UDDI是一个注册核心,用于发布、查找跟描述Web效劳。
RESTful API是一种轻量级、机动的Web效劳架构,遵守REST原则。
<!-- wsdl.xml -->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="AddRequest">
<part name="number1" type="xs:int"/>
<part name="number2" type="xs:int"/>
</message>
<message name="AddResponse">
<part name="result" type="xs:int"/>
</message>
<portType name="AddService">
<operation name="add">
<input message="tns:AddRequest"/>
<output message="tns:AddResponse"/>
</operation>
</portType>
<binding name="AddServiceBinding" type="tns:AddService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="add">
<soap:operation soapAction="add"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="AddService">
<endpoint name="AddServiceEndpoint" binding="tns:AddServiceBinding" address="http://localhost:8080/addService"/>
</service>
</definitions>
import zeep
client = zeep.Client('http://localhost:8080/addService?wsdl')
result = client.add(10, 20)
print(result)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/add/<int:num1>/<int:num2>', methods=['GET'])
def add(num1, num2):
return jsonify(result=num1 + num2)
if __name__ == '__main__':
app.run(debug=True)
import requests
response = requests.get('http://localhost:5000/add/10/20')
print(response.json())
控制W3C Web效劳对开辟者来说至关重要。本文介绍了W3C Web效劳的基本不雅点、关键技巧,并供给了SOAP跟RESTful API的实战教程。盼望读者经由过程进修本文,可能轻松入门W3C Web效劳。