Spring Web Services এ WSDL এবং XSD এর কনফিগারেশন

WSDL এবং Schema Validation - স্প্রিং ওয়েব সার্ভিসেস (Spring Web Services) - Java Technologies

346

WSDL এবং XSD কী?

  • WSDL (Web Services Description Language)
    WSDL একটি XML ভিত্তিক ভাষা যা ওয়েব সার্ভিসের ফাংশনালিটি বর্ণনা করে। এটি ক্লায়েন্ট এবং সার্ভারের মধ্যে যোগাযোগের জন্য প্রয়োজনীয় কনফিগারেশন প্রদান করে।
    উদাহরণস্বরূপ, WSDL ফাইলে সার্ভিসের নাম, পোর্ট টাইপ, অপারেশন, এবং ডেটা টাইপ বর্ণিত থাকে।
  • XSD (XML Schema Definition)
    XSD একটি স্ট্যান্ডার্ড যা XML ডকুমেন্টের ডেটার গঠন এবং সীমাবদ্ধতাগুলি বর্ণনা করে। WSDL ফাইলে ব্যবহৃত XML মেসেজ ফরম্যাটের গঠন XSD দ্বারা নির্ধারিত হয়।

Spring Web Services এ WSDL এবং XSD ব্যবহারের গুরুত্ব

  • SOAP বার্তা স্ট্রাকচার
    SOAP বার্তার ডেটা টাইপ এবং ফরম্যাট সংজ্ঞায়িত করতে XSD ব্যবহার করা হয়।
  • ক্লায়েন্ট-সার্ভার চুক্তি (Contract-First Approach)
    WSDL এবং XSD ব্যবহার করে ক্লায়েন্ট ও সার্ভারের মধ্যে ডেটা বিনিময়ের কাঠামো নির্ধারিত হয়।

Spring Web Services এ WSDL এবং XSD কনফিগারেশন

WSDL ফাইল তৈরি

  1. WSDL ফাইল তৈরি করুন
    একটি WSDL ফাইল তৈরি করুন যেখানে সার্ভিসের অপারেশন এবং ডেটা টাইপ নির্ধারণ করা হয়েছে।

    উদাহরণ:

    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" 
                 xmlns:tns="http://example.com/webservice" 
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                 name="EmployeeService" 
                 targetNamespace="http://example.com/webservice">
        
        <types>
            <xsd:schema targetNamespace="http://example.com/webservice">
                <xsd:element name="GetEmployeeRequest">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="id" type="xsd:int"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="GetEmployeeResponse">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="name" type="xsd:string"/>
                            <xsd:element name="salary" type="xsd:double"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:schema>
        </types>
        
        <message name="GetEmployeeRequest">
            <part name="parameters" element="tns:GetEmployeeRequest"/>
        </message>
        <message name="GetEmployeeResponse">
            <part name="parameters" element="tns:GetEmployeeResponse"/>
        </message>
        
        <portType name="EmployeeServicePortType">
            <operation name="GetEmployee">
                <input message="tns:GetEmployeeRequest"/>
                <output message="tns:GetEmployeeResponse"/>
            </operation>
        </portType>
        
        <binding name="EmployeeServiceBinding" type="tns:EmployeeServicePortType">
            <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            <operation name="GetEmployee">
                <soap:operation soapAction="http://example.com/webservice/GetEmployee"/>
                <input>
                    <soap:body use="literal"/>
                </input>
                <output>
                    <soap:body use="literal"/>
                </output>
            </operation>
        </binding>
        
        <service name="EmployeeService">
            <port name="EmployeeServicePort" binding="tns:EmployeeServiceBinding">
                <soap:address location="http://localhost:8080/ws"/>
            </port>
        </service>
    </definitions>
    

XSD ফাইল তৈরি

XSD ফাইল তৈরি করে XML ডেটার কাঠামো এবং বৈধতা নিয়ন্ত্রণ করতে হবে।

উদাহরণ:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           targetNamespace="http://example.com/webservice" 
           xmlns="http://example.com/webservice" 
           elementFormDefault="qualified">

   <xs:element name="GetEmployeeRequest">
       <xs:complexType>
           <xs:sequence>
               <xs:element name="id" type="xs:int"/>
           </xs:sequence>
       </xs:complexType>
   </xs:element>

   <xs:element name="GetEmployeeResponse">
       <xs:complexType>
           <xs:sequence>
               <xs:element name="name" type="xs:string"/>
               <xs:element name="salary" type="xs:double"/>
           </xs:sequence>
       </xs:complexType>
   </xs:element>

</xs:schema>

Spring Configuration

  1. Endpoint তৈরি
    একটি Spring Endpoint তৈরি করতে হবে যা SOAP বার্তা হ্যান্ডল করবে।

    উদাহরণ:

    @Endpoint
    public class EmployeeEndpoint {
        private static final String NAMESPACE_URI = "http://example.com/webservice";
    
        @PayloadRoot(namespace = NAMESPACE_URI, localPart = "GetEmployeeRequest")
        @ResponsePayload
        public GetEmployeeResponse getEmployee(@RequestPayload GetEmployeeRequest request) {
            GetEmployeeResponse response = new GetEmployeeResponse();
            response.setName("John Doe");
            response.setSalary(75000);
            return response;
        }
    }
    
  2. WSDL এবং XSD Bean Configuration
    Spring এর Application Context এ WSDL এবং XSD কনফিগার করুন।

    উদাহরণ:

    @Bean
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema employeeSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("EmployeeServicePort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("http://example.com/webservice");
        wsdl11Definition.setSchema(employeeSchema);
        return wsdl11Definition;
    }
    
    @Bean
    public XsdSchema employeeSchema() {
        return new SimpleXsdSchema(new ClassPathResource("employee.xsd"));
    }
    

WSDL এবং XSD এর সুবিধা

  • ডেটা স্ট্রাকচার এবং সার্ভিস ইন্টারফেস নির্ধারণে স্বচ্ছতা প্রদান করে।
  • ক্লায়েন্ট-সার্ভারের মধ্যে যোগাযোগে ভুলের সম্ভাবনা হ্রাস করে।
  • বড় আকারের এন্টারপ্রাইজ সিস্টেমে পুনর্ব্যবহারযোগ্য এবং একক ডেটা চুক্তি নিশ্চিত করে।

Spring Web Services এ WSDL এবং XSD কনফিগারেশন SOAP ওয়েব সার্ভিসের কার্যকারিতা বাড়ায় এবং এটি ক্লায়েন্ট-সার্ভারের মধ্যে নির্ভরযোগ্য যোগাযোগের সুযোগ দেয়।

Content added By
Promotion

Are you sure to start over?

Loading...