トップ 差分 一覧 ソース 置換 検索 ヘルプ PDF RSS ログイン

SOAPとREST

用語説明

http://www.atmarkit.co.jp/ait/articles/1002/26/news094.html

比較

SOAP REST JSON
学習容易性 ×
コーディング量(自動生成分は除く) ×
テストのし易さ × ×
開発ツール × ×
導入の容易性 ×
開発にかかるトータル時間 ×
複雑なデータの入力 × ×
複雑なデータの出力
厳密な型チェック × ×
汎用性(扱える開発言語の種類) ×
標準化団体 W3C - ecma
拡張性(WS-*) × ×

SOAP

 Java

JAX-WSという、SOAPを扱うためのAPIがある。
JavaでSOAP

 PHP

PHPでSOAP

 JavaScript


REST

 Java

JavaでREST

 PHP

PHPでREST

 JavaScript



REST

http://xmlconsortium.org/wg/web2.0/teigensho/4--REST-SOAP.html
明確な仕様はないが、
RSSのような「URLにアクセスするとXMLが返ってくるようなもの」

 RESTアクセスのサンプル

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function requestRest(){

    var endpoint = "http://ホスト名/WebSite1/WebService.asmx";  // 送信先
    var param1 = "keywork";                                      // パラメータ

    // URLを生成
    var url = endpoint + "/getHello?str=" + encodeURI(param1) + "&dummy="+(new Date().getTime());

    // XMLHttpRequestを作成
    try {
        xmlhttp = new XMLHttpRequest();     // Netscape, Firefoxなど
    } catch (e){
        try {
            xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");     // IE
        } catch (e){
            try {
                xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");  // IE
            } catch (e){
                // XMLHttpRequestの作成に失敗
            }
        }
    }
    
    xmlhttp.onreadystatechange = method1;    // レスポンスを受け取った時に呼ばれるメソッドを指定
    xmlhttp.open('GET', url, true);
    xmlhttp.setRequestHeader ("Content-Type","text/xml; charset=utf-8");

    xmlhttp.send();  // RESTで送信

}

function method1() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        alert(xmlhttp.responseText);    // 結果をデバッグ表示
    }
}

SOAP

XMLでメッセージをやり取りする。
リクエストをXMLで送って、XMLを受け取る。

 SOAPアクセスサンプル

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function requestSoap(){

    var endpoint = "http://ホスト名/WebSite1/WebService.asmx";  // 送信先
    var param1 = "keywork";                                      // パラメータ

    // SOAPメッセージを作成
    var msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n\
               xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n\
               xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n\
  <soap:Body>\n\
    <getHello xmlns=\"http://tempuri.org/\">\n\
      <str>" + param1 + "</str>\n\
    </getHello>\n\
  </soap:Body>\n\
</soap:Envelope>";

    // XMLHttpRequestを作成
    try {
        xmlhttp = new XMLHttpRequest();     // Netscape, Firefoxなど
    } catch (e){
        try {
            xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");     // IE
        } catch (e){
            try {
                xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");  // IE
            } catch (e){
                // XMLHttpRequestの作成に失敗
            }
        }
    }
    
    xmlhttp.onreadystatechange = method2;    // レスポンスを受け取った時に呼ばれるメソッドを指定
    xmlhttp.open('POST', endpoint, true);
    xmlhttp.setRequestHeader ("Content-Type","text/xml; charset=utf-8");
    xmlhttp.setRequestHeader ("SOAPAction","\"http://tempuri.org/getHello\"");

    xmlhttp.send(msg);  // SOAPメッセージを送信
}

function method2() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        xmlDoc = xmlhttp.responseXML;   // 結果をDOMオブジェクトとして取得
    }
}

[カテゴリ: プログラミング言語 > Java]

[通知用URL]



  • Hatenaブックマークに追加
  • livedoorクリップに追加
  • del.icio.usに追加
  • FC2ブックマークに追加

最終更新時間:2015年11月29日 14時24分02秒