You are on page 1of 17

:

,
(730)
2013.
________________________


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)
. W3C1
- --
. ,
.

. ,
w . ,
.
:


(IE, Firefox, Chrome). w
HTML
.

Web servisi su namenjeni programskom kodu (C#, PHP, Java, C++)


.
w
(npr. XML, SOAP, JSON)



.

.
,
.
.
-
URLa.

http://wsf.cdyne.com/WeatherWS/Weather.asmx
1W3C (. World Wide Web Consortium)

2

URL

,
:

GetCityForecastByZIP -
7 ZIP

GetCityWeatherByZIP - ZIP

GetWeatherInformation - ID-


.
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 .
:
?
<%@ WebService Language="C#"
1
Class="WebServisi. WebServis " %>

CodeBehind="

WebServis.asmx.cs"


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

.
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 .
, Saberi
3 8, XML:
?
1

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope
3 instance"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-

4 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
6
7

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

<x>3</x>

<y>8</y>

1
0

</Saberi>
</soap:Body>

1
</soap:Envelope>
1

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/XMLSchemainstance"
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
<SaberiResult>11</SaberiResult>
8
</SaberiResponse>
9
</soap:Body>
1
0 </soap:Envelope>
SOAP .
,
XML
.
, 99% SOAP

SOAP WSDL
. ,
SOAP SOAP .

[WebService] [WebMethod] .

2.2
,
. Visual Studio
. .
8

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.urlservera.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 .

11

REST
, , .
, URL

-
17
- ://www..//17.
w
http://www.url-servera.com/Proizvod(17). URL-
HTTP REST

:

GET

PUT

POST

DELETE
URL
HTTP REST .

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

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

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) -
291

XML

http://odata.netflix.com/v2/Catalog/Titles('red')
red

XML

REST
- Netflix (
OData
REST ). Netflix
REST XML
JSON :
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
.
13

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 :

?
1 [ServiceContract]
2 public interface IProizvodRESTServis
3{
4

[OperationContract]

[WebInvoke(Method = "GET",
14

UriTemplate = "/Proizvod/{id}",

ResponseFormat = WebMessageFormat.Json)]

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 :
?
1 $.ajax({
2

type: "GET",

url: "/ProizvodRESTServis.svc/Proizvod/17",

15

success: function(odgovor){

5
6

alert(odgovor.NazivProizvoda);
}

7 })
REST x
.
x URL , HTTP
.

REST x
.

3.5
REST
SOAP . REST
,

JavaScript x
. REST

.
REST
.

16

You might also like