Different Between SOAP url and REST url

Currently I am using Axis2 to make some REST API. And I am confused about the difference between a SOAP style url and a REST style url. Can anyone explain this?

For example, for an server API written in java like this:

package cn.edu.xidian;

public class Salary {
    public int getSalary(String name) {
        if ( name.equals("zhangsan") ) {
            return 3000;
        } else if ( name.equals("lisi") ) {
            return 4000;
        } else 
            return 5000;
    }
}

The REST url for GET this service will look like:

http://localhost:8080/axis2/services/SalaryService/getSalary?name=zhangsan

If my comprehension is right, this url goes into the server side API, call the method 'getSalary' with an argument 'name' equals 'zhangsan', and then the RESTful output in the browser will look like:

<ns:getSalaryResponse>
    <ns:return>3000</ns:return>
</ns:getSalaryResponse>

Then what will a SOAP style URL and related stuff look like?


A URL in itself is not SOAP or REST , it's a URL. (are the adjectives SOAPy and RESTful?)

First, the example of your REST resource:

  http://localhost:8080/axis2/services/SalaryService/getSalary?name=zhangsan

looks you're building some type RPC over HTTP, like your trying to use quasi-REST structure to implement a remote function calls. Many would not consider this good REST.

SOAP is an XML encoded messaging system implemented over some transport layer.

SOAP is not limited to HTTP for transport while REST is by it's nature. The fact you can HTTP for transport for SOAP via URLs and structure those URLs however you want is inconsequential. Also, the fact that most SOAP APIs are probably mostly implemented across HTTP in reality is also irrelevant.

REST is a concept of using the HTTP verbs (PUT, GET, POST, etc...) and response codes as they are intended as the protocol to access and control resources. This includes for creation, modification, deletion, etc... of those resources.

The structure of a SOAP url might in fact look exactly like a REST api, but with REST, the structure should strongly reflect the logical structure of the resource. You don't have to to be fully RESTful, but if not your REST API wouldn't be developer friendly. SOAP isn't necessarily required to have nice urls that reflect data structure as you can provide a WSDL which outlines and can describe the soap services available with just about any URL structure you use. In fact, I've seen quite a few totally acceptable SOAP services that had urls to that seem to be arbitrarily dropped in over the course of time, not reflecting any type of structure.

链接地址: http://www.djcxy.com/p/71396.html

上一篇: 弱自赋值使用的解释

下一篇: SOAP网址和REST网址不同