البرامج في هذه الأيام أكثر قوة من أي وقت مضى. يمكنها توفير الكثير من المعلومات والوظائف للمستخدمين. مع قدرات التطبيقات القوية بشكل متزايد، هل تساءلت كيف يتم تحقيق كل ذلك؟
نوع من الملفات الذي يظهر غالبًا في تطور التطبيقات هو ملف WSDL، لكن ما هو؟
ما هو ملف WSDL؟
WSDL (لغة وصف خدمات الويب) تتيح لمختلف التطبيقات التواصل مع بعضها البعض عبر الشبكة بطريقة موحدة. إنه يربط مقدمي خدمات الويب والمستهلكين، مما يسمح بتبادل البيانات بين الطرفين، وليس محدودًا بهما فقط.
تشتهر ملفات WSDL أيضًا بتوفير وصف وفير بشأن قدرات خدمة الويب، وخاصة لخدمات الويب المعتمدة على SOAP. تُكتب ملفات WSDL بلغة XML (لغة الترميز القابلة للتوسع) وهي ضرورية لاختبار واجهات برمجة تطبيقات SOAP.
الأهم من ذلك، تعتبر ملفات WSDL ذات أهمية بسبب تعريف اتفاقية رسمية بين مقدم خدمة الويب ومستهلك الخدمة. تُظهر ملفات WSDL ما هي العمليات المتاحة، وتنسيق وهيكل الرسائل، وغيرها من التفاصيل المهمة المطلوبة عند استخدام خدمة الويب.
هيكلة ملفات WSDL مع أمثلة
تمتلك ملفات WSDL مكونات رئيسية توفر المعلومات اللازمة لاستخدامها. ستعرض هذه المقالة أجزاء من ملف WSDL بلغة XML، باستخدام خدمة ويب للطقس كمثال.
الأنواع type
يستخدم قسم type
في ملفات WSDL لتعريف أنواع البيانات التي سيتم استخدامها في عمليات خدمة الويب.
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/weather">
<element name="City" type="string"/>
<element name="Weather" type="string"/>
</schema>
</types>
يحدد هذا المثال هيكل العناصر، بما في ذلك أسمائها City
و Weather
التي هي من نوع string
.
الرسالة message
يحدد قسم message
عناصر البيانات التي يتم تبادلها بين مقدم خدمة الويب ومستخدم الخدمة. في الأمثلة أعلاه، يمكنك رؤية أسماء الرسائل GetWeatherRequest
و GetWeatherResponse
.
<message name="GetWeatherRequest">
<part name="City" element="tns:City"/>
</message>
<message name="GetWeatherResponse">
<part name="Weather" element="tns:Weather"/>
</message>
هنا، يتم تعريف رسائل GetWeatherRequest
و GetWeatherResponse
مع جزء يحدد عناصر البيانات المرسلة أو المستلمة.
نوع المنفذ portType
يصف قسم portType
مجموعة من العمليات التي يمكن تنفيذها بواسطة خدمة الويب، مثل اسم العملية GetWeather
. إنه يعرف الواجهة التجريبية للخدمة، مدرجًا العمليات مع مدخلاتها tns:GetWeatherRequest
والرسائل الناتجة tns:GetWeatherResponse
.
<portType name="WeatherServicePortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
يوضح المثال أعلاه WeatherServicePortType
كعملية محددة GetWeather
مع رسائل مدخلات ومخرجات محددة.
الربط binding
يحدد قسم binding
كيفية ربط العمليات التجريبية المعرّفة في portType
ببروتوكول ملموس للتواصل. إنه يحدد التفاصيل مثل تنسيق الرسالة والبروتوكول (مثل SOAP).
<binding name="WeatherServiceSoapBinding" type="tns:WeatherServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/weather/GetWeather"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
في هذا المثال، يتم تعريف WeatherServiceSoapBinding
مع SOAP كبروتوكول الربط، موفرًا تفاصيل حول تنسيق الرسالة والنقل.
المنفذ port
يحدد قسم port
عنوان الشبكة الذي يمكن الوصول إلى خدمة الويب من خلاله.
<service name="WeatherService">
<port name="WeatherServicePort" binding="tns:WeatherServiceSoapBinding">
<soap:address location="http://example.com/weather/service"/>
</port>
</service>
هنا، يتم تعريف WeatherService
مع WeatherServicePort
الذي يستخدم الربط SOAP، وعنوانه مشخص كـ http://example.com/weather/service
.
أمثلة على ملفات WSDL
مثال ملف WSDL لخدمة الطقس البسيطة
بتجميع مقتطفات الكود المختلفة للمكونات الرئيسية المقدمة في القسم السابق، يمكننا دمجها معًا وإنشاء ملف WSDL لخدمة الطقس البسيطة.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/weather"
targetNamespace="http://example.com/weather">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/weather">
<element name="City" type="string"/>
<element name="Weather" type="string"/>
</schema>
</types>
<message name="GetWeatherRequest">
<part name="City" element="tns:City"/>
</message>
<message name="GetWeatherResponse">
<part name="Weather" element="tns:Weather"/>
</message>
<portType name="WeatherServicePortType">
<operation name="GetWeather">
<input message="tns:GetWeatherRequest"/>
<output message="tns:GetWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherServiceSoapBinding" type="tns:WeatherServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetWeather">
<soap:operation soapAction="http://example.com/weather/GetWeather"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WeatherService">
<port name="WeatherServicePort" binding="tns:WeatherServiceSoapBinding">
<soap:address location="http://example.com/weather/service"/>
</port>
</service>
</definitions>
في هذا المثال البسيط لخدمة الطقس، يمكن ملاحظة أن:
- تعمل خدمة الويب تحت النطاق
http://example.com/weather
. - تحدد نوعين بسيطين من البيانات:
City
وWeather
. - يوجد رسالتان،
GetWeatherRequest
وGetWeatherResponse
، تحددان بيانات المدخلات والمخرجات لعمليةGetWeather
. - يعرف نوع المنفذ
WeatherServicePortType
عمليةGetWeather
. - تحدد
WeatherServiceSoapBinding
أن التواصل سيكون باستخدام SOAP مع نمط ونقل محددين. - تحتوي خدمة
WeatherService
على منفذ يسمىWeatherServicePort
يستخدم الربط SOAP، وعنوانه محدد كـhttp://example.com/weather/service
.
مثال ملف WSDL لخدمة التجارة الإلكترونية المعقدة
ها هو مثال أكثر تعقيدًا لملف WSDL لخدمة التجارة الإلكترونية يتضمن عمليات متعددة وأنواع بيانات وميزات.
?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://example.com/ecommerce"
targetNamespace="http://example.com/ecommerce">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com/ecommerce">
<element name="Product">
<complexType>
<sequence>
<element name="ProductId" type="string"/>
<element name="ProductName" type="string"/>
<element name="Price" type="decimal"/>
</sequence>
</complexType>
</element>
<element name="Order">
<complexType>
<sequence>
<element name="OrderId" type="string"/>
<element name="CustomerName" type="string"/>
<element name="Products" type="tns:Product" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="GetProductRequest">
<part name="ProductId" element="tns:ProductId"/>
</message>
<message name="GetProductResponse">
<part name="Product" element="tns:Product"/>
</message>
<message name="PlaceOrderRequest">
<part name="Order" element="tns:Order"/>
</message>
<message name="PlaceOrderResponse">
<part name="Confirmation" type="string"/>
</message>
<portType name="ECommerceServicePortType">
<operation name="GetProduct">
<input message="tns:GetProductRequest"/>
<output message="tns:GetProductResponse"/>
</operation>
<operation name="PlaceOrder">
<input message="tns:PlaceOrderRequest"/>
<output message="tns:PlaceOrderResponse"/>
</operation>
</portType>
<binding name="ECommerceServiceSoapBinding" type="tns:ECommerceServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetProduct">
<soap:operation soapAction="http://example.com/ecommerce/GetProduct"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="PlaceOrder">
<soap:operation soapAction="http://example.com/ecommerce/PlaceOrder"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ECommerceService">
<port name="ECommerceServicePort" binding="tns:ECommerceServiceSoapBinding">
<soap:address location="http://example.com/ecommerce/service"/>
</port>
</service>
</definitions>
في هذا المثال المعقد لخدمة التجارة الإلكترونية، يمكن ملاحظة أن:
- تم تعريف أنواع بيانات معقدة
Product
وOrder
مع عناصر متداخلة (مثلProductID
وProductName
وPrice
) وتسلسلات. - تم تعريف عمليات متعددة
GetProduct
وPlaceOrder
ضمنECommerceServicePortType
. - تم تعريف الرسائل
GetProductRequest
وGetProductResponse
وPlaceOrderRequest
وPlaceOrderResponse
لكل عملية، تحدد بيانات المدخلات والمخرجات. - تحدد الربط SOAP
ECommerceServiceSoapBinding
تفاصيل التنسيق للتواصل باستخدام SOAP. - تحتوي الخدمة
ECommerceService
على منفذ يسمىECommerceServicePort
يستخدم الربط SOAP، وعنوانه محدد كـhttp://example.com/ecommerce/service
.
تعديل ملفات WSDL باستخدام Apidog
نظرًا لأن ملفات WSDL شائعة نسبيًا في مشهد تطوير البرمجيات، قد تضطر إلى تعديل أو إنشاء واحدة بنفسك. مع وجود العديد من منصات واجهات برمجة التطبيقات هناك، يعد Apidog خيارًا ممتازًا.
يسمح Apidog للمطورين ومقدمي خدمات الويب ومستخدمي خدمات الويب من أي خلفية بإجراء انتقال سلس من منصات واجهات برمجة التطبيقات الأخرى إلى Apidog.
لحسن الحظ، يغطي Apidog أيضًا استيراد ملفات WSDL! إذا كنت مهتمًا بتجربة ذلك، تأكد من تحميل Apidog باستخدام الأزرار أدناه.
لا تنسَ تسجيل الدخول وبدء مشروع جديد بمجرد دخولك. إذا كنت بحاجة إلى المساعدة، تحقق من وثائق مساعدة Apidog.
استيراد واجهة برمجة التطبيقات SOAP الخاصة بك إلى Apidog من ملف WSDL

بمجرد فتح مشروع جديد، انقر على زر "الإعدادات" على الشريط الجانبي العمودي الموجود على الجانب الأيسر من نافذة Apidog. ثم، انقر على السهم 2 والسهم 3 بهذا الترتيب.
اختبار واجهة برمجة التطبيقات SOAP بسهولة على Apidog

إذا قمت باستيراد ملف WSDL بنجاح، يجب أن ترى اسمه على الجانب الأيسر من الشاشة، كما هو موضح حول السهم 1.
للبدء في تعديل ملف WSDL، انقر على الأسهم 2 إلى 4 بالترتيب التصاعدي، وستكون جاهزًا!
الخاتمة
مع ملفات WSDL المستندة إلى XML (لغة الترميز القابلة للتوسع)، يكون من السهل قليلاً فهمها. يمكن أن تختلف ملفات WSDL في التعقيد اعتمادًا على مدى دقة الأوصاف والوظائف لخدمة الويب.