You are on page 1of 16

L

1.

.......................................................................................................................................... 2
1.1 ? .......................................................................................................................... 2

2. SOAP .................................................................................................................................... 4
2.1 SOAP ............................................................................................................ 5
2.2 ................................................................................................................... 8
2.3 .......................................................................................................................................... 10
3. REST ................................................................................................................................... 11
3.1 REST ............................................................................................................... 12
3.2 SOAP .............................................................................................. 13
3.3 REST ........................................................................................................... 13
3.4 REST ............................................................................................................... 14
3.5 .......................................................................................................................................... 15

1.
1.1 ?
(. Web service)
. W3C 1 -- . ,
.

. , w .
, .
:

(IE, Firefox,
Chrome). w HTML
.
Web servisi su namenjeni programskom kodu (C#, PHP, Java, C++)
. w
(npr. XML,
SOAP, JSON)



.
.
,
. .
-
URLa.
URL http://wsf.cdyne.com/WeatherWS/Weather.asmx
,
:

GetCityForecastByZIP - 7 ZIP

GetCityWeatherByZIP - ZIP
GetWeatherInformation - ID-

W3C (. World Wide Web Consortium)


. XML
.
XML .
w
SOAP . .

2. SOAP
SOAP SOAP
.
:

(Service Provider) -
.
(Service Requester) -
.

f(x) .

. SOAP -XML
. SOAP - XML ,
, ,
SOAP - XML .
XML- .

, ""
. URL-a.
, URL-
http://wsf.cdyne.com/WeatherWS/Weather.asmx
URL ?WSDL .
http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL .
URL XML ,
. XML WSDL (Web Services
Description Language).
, .
URL
.

WSDL
(WSDL). UDDI (Universal Description, Discovery and
Integration)
.
WSDL .
, WSDL
.

UDDI . w
.

2.1 SOAP
C#, ASP.NET Visual Studio.
Add >> New Item... >> Visual C# >> Web, "Web service"
. ( WebServis) Visual Studio
:

WebServis.asmx - URL-
WebServis.asmx.cs - C#

ASMX .
:
?
1

<%@ WebService Language="C#" CodeBehind=" WebServis.asmx.cs" Class="WebServisi.


WebServis " %>


http://...../WebServis.asmx. asmx.cs
5

.
.
ASMX.CS URL-a.
asmx.cs :
?
1 [WebService(Namespace = "http://www.moj-web-servis.org/")]
2 public class MojWebServis : System.Web.Services.WebService
3 {
4

[WebMethod]

public DateTime Sad()

7
8

return DateTime.Now;
}

9
10 [WebMethod]
11 public int Saberi(int x, int y)
12 {
13

return x + y;

14 }
15}
, [WebService]
.
[WebMethod]. URL
WebServis.asmx .
SOAP
SOAP -XML . ,
6

Saberi 3 8,
XML:
?
1 <?xml version="1.0" encoding="utf-8"?>
2 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
5 <soap:Body>
6

<Saberi xmlns="http://www.moj-web-servis.org/">

<x>3</x>

<y>8</y>

</Saberi>

10 </soap:Body>
11</soap:Envelope>
x y - XML-a SOAP (.
SOAP Envelope). SOAP - XML
:
?
1 <?xml version="1.0" encoding="utf-8"?>
2 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
5 <soap:Body>
6

<SaberiResponse xmlns="http://www.moj-web-servis.org/">

7
8

<SaberiResult>11</SaberiResult>
</SaberiResponse>

9 </soap:Body>
10</soap:Envelope>
SOAP . ,
XML
.
, 99% SOAP
SOAP
WSDL .
, SOAP SOAP .

[WebService] [WebMethod] .

2.2
,
. Visual Studio .
. Add >> Service Reference URL
. Go
.

(Namespace).
, Visual Studio SOAP
.
.
. , SOAP-XML
, , SOAP-XML ,
.
, MojWebServis ,
:
var ws = new WebServisi.MojWebServisSoapClient();
var rezultat = ws.Saberi(3, 6);
var datum = ws.Sad();


w Sad() Saberi(). Client
SOAP .
.

2.3
W
. ASP.NET-
SOAP Visual Studio
.
SOAP . SOAP
- REST SOAP
HTTP .

10

3. REST
REST ,
. ,
,
, .
CRUD .
:

GetProduct ili GetProducts


InsertProduct
UpdateProduct
DeleteProduct

.
URL . REST .
URL- URL
.
, http://www.url-servera.com
, URL:

http://www.url-servera.com/Proizvod -
http://www.url-servera.com/Osoba -
http://www.url-servera.com/Kompanija -

URL- REST
HTTP . HTTP
URL-. GET
POST . HTTP
PUT, DELETE HEAD .
REST
, , . ,
URL - 17 - ://www..//17.
w http://www.urlservera.com/Proizvod(17). URL- HTTP
REST
:


11

GET

PUT

POST

DELETE

URL HTTP
REST .
(C#, Java, JavaScript, PHP)
HTTP
XML .
XML, JSON
.

3.1 REST
REST . Netflix
, .
, .
URL- , :

http://odata.netflix.com/v2/Catalog/People - XML
http://odata.netflix.com/v2/Catalog/Genres - XML

http://odata.netflix.com/v2/Catalog/Titles - XML

Netflix REST
URL:

http://odata.netflix.com/v2/Catalog/People(291) - XML
291
http://odata.netflix.com/v2/Catalog/Titles('red') - XML
red

REST - Netflix
(
OData REST ).
Netflix REST XML
JSON :
12

http://odata.netflix.com/v2/Catalog/People(291)?$format=json
http://odata.netflix.com/v2/Catalog/Titles('red') )?$format=json

, ,
. Netflix w
- OData
. ,
OData, Netflix
REST .

3.2 SOAP
REST (. SOAP)
. REST w SOAP ,
SOAP -X .
SOAP
SOAP .
JavaScript x REST
.
.
,
-X .
,

.

3.3 REST
REST REST
. C#
REST WCF .
Visual Studio, w
WCF (Add > New Item > Wb > WCF Service) :
REST
. WCF
ProizvodRESTServis, IProizvodRESTServis.cs
:

13

?
1[ServiceContract]
2public interface IProizvodRESTServis
3{
4 [OperationContract]
5 [WebInvoke(Method = "GET",
6

UriTemplate = "/Proizvod/{id}",

ResponseFormat = WebMessageFormat.Json)]

8 string VratiDetaljeProizvoda(string id);


9}
w
VratiDetaljeProizvoda. -
URI /Proizvod/{id}.

JSON

URL

/ProizvodRESTServis.svc/Proizvod/17 .
HTTP GET
.
REST Dt
. Dt
. Dt Netflix
.

3.4 REST
REST
SOAP ,
. REST
URL-a .

URL . x REST
ID- 17 :
14

?
1$.ajax({
2 type: "GET",
3 url: "/ProizvodRESTServis.svc/Proizvod/17",
4 success: function(odgovor){
5 alert(odgovor.NazivProizvoda);
6 }
7})
REST x
. x
URL , HTTP
.
REST x .

3.5
REST SOAP .
REST
,
JavaScript x
. REST
.
REST
.

15

You might also like