Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need WSDL with SOAP?

Ok, so I'm learning about SOAP. Here is a SOAP request and a SOAP response, along with the WSDL.

Why do we need the WSDL file? Why do we need portType, like

  <wsdl:portType name="GetEndorsingBoarderPortType">
      <wsdl:operation name="GetEndorsingBoarder">
         <wsdl:input message="es:GetEndorsingBoarderRequest"/>
         <wsdl:output message="es:GetEndorsingBoarderResponse"/>
         <wsdl:fault message="es:GetEndorsingBoarderFault"/>
      </wsdl:operation>
   </wsdl:portType>

Can't the server determine which method to use and which response to send only by parsing the SOAP request?

And why does the example use the namespace xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" in the Envelope? Can't it just send a simple XML with the needed tags, parse it and send an answer?

like image 634
Hello Lili Avatar asked Dec 10 '25 20:12

Hello Lili


1 Answers

Many questions, I guess you ask out of curiosity so I try to answer them "just" top-down and hopefully there are some hints that help you orient further:

Can't the server determine which method to use and which response to send only by parsing the SOAP request?

It actually does. The WSDL from the client perspective is only used to tell you what the service is (decription of the service) and - in case of the PHP SoapClient - to assist you to access the service (take the only with a grain of salt, using SoapClient in WSDL mode is commonly the recommended way to use it).


Why do we need the WSDL file?

It contains the service description in a machine-readable format. You need it if you need to learn about the service. You don't need it if you know the service in an out and can just type together every request you need to (not recommended if the service deals with more than a single operation and complex types).


Why do we need portType [... ?]

To quote from the specification:

portType, which is a set of abstract operations. Each operation refers to an input message and output messages.

It's one of the six major elements which define a service. More details are available about port-types here: http://www.w3.org/TR/wsdl#_porttypes - depending on service these can differ and there are services without PortTypes as well IIRC (perhaps only in earlier SOAP versions, can't say for sure from top of my head).


And why does the example use the namespace xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" in the Envelope? Can't it just send a simple XML with the needed tags, parse it and send an answer?

That is "just" sending the XML. Those elements follow the nomenclatura of XML Namespaces, that's all. So to answer the question verbatim: No it can't just send simple (non-namespaced) XML as it needs to know the tags in their namespace to identify them.

This is done to separate the SOAP envelope from the other information in the message body which is XML encoded as well. Imagine a service message deals as well with an envelope or a message or a header. A clash of names would be highly likely, therefore the namespaces are important to differ between the envelope of the SOAP message and an envelope as an object that is send or retrieved from the service.

like image 93
hakre Avatar answered Dec 13 '25 10:12

hakre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!