-2

Let's say that I have an XML and it's a request to a service. How can I tell if it's a RESTful service or SOAP service request?

What are the distinguishable characteristics that could be find, based only on request content?

Piotrek Hryciuk
  • 785
  • 10
  • 23
  • How can a file be a request? Please specify your question. Can you post the file content? – Mikkk Mar 13 '18 at 19:08
  • I meant XML content. This is hypothetical question. – Piotrek Hryciuk Mar 13 '18 at 19:17
  • OK. Well, if your "XML content" represents a SOAP request being sent to the service as POST, I'd say it's SOAP. If the XML is the content or payload itself (without being interpreted on server side), it depends on the kind of URL you sent it to. If the URL identifies a resource, chances are that it's a REST request. – Mikkk Mar 13 '18 at 19:25
  • Is the XML based of a WSDL? If so, you are with high certainty dealing with a SOAP service. If you don't know, you might look at the [structure](https://en.wikipedia.org/wiki/SOAP) of the XML. If it contains a SOAP envelope and body and maybe a header, it may have been issued from a SOAP service. If the document doesn't follow this structure it probably was issued from a plain HTTP or even REST service. Note that some pseudo-REST services (that are actually RPC) may return content appropriate for SOAP as well. But why do you even care as long as the remote server understood the request – Roman Vottner Mar 13 '18 at 19:57
  • Possible duplicate of [SOAP vs REST, when to use one and not the other?](https://stackoverflow.com/questions/20101374/soap-vs-rest-when-to-use-one-and-not-the-other) – Ming Chan Apr 07 '18 at 02:41

1 Answers1

1

Here's an example of a SOAP request, this is an example of a call to the get cities by country API on http://www.webservicex.net/New/Home/ServiceDetail/56:

POST /globalweather.asmx HTTP/1.1
Host: www.webservicex.net
User-Agent: curl/7.45.0
Accept: */*
Content-Type: text/xml
Content-Length: 442

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:tns="http://www.webserviceX.NET">
    <soap:Body>
        <GetCitiesByCountry xmlns="http://www.webserviceX.NET">
            <CountryName>France</CountryName>
        </GetCitiesByCountry>
    </soap:Body>
</soap:Envelope>

You can see the distinguishing characteristics of the XML body.

A REST call to a generic service could contain any XML data the API defines.

This might look like:

POST /getaddress HTTP/1.1
Host: localhost:3000
User-Agent: curl/7.45.0
Accept: */*
Content-Length: 85
Content-Type: text/xml

<location>
    <latitude>34.067225</latitude>
    <longitude>-118.474307</longitude>
</location>
Terry Lennox
  • 29,471
  • 5
  • 28
  • 40