16
Веб сервиси и ХМL интерфејс

Web Servisi i XML Interfejs

Embed Size (px)

DESCRIPTION

REST i SOAP web servisi

Citation preview

  • L

  • 1

    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

  • 2

    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.

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

    GetCityForecastByZIP - 7 ZIP

    GetCityWeatherByZIP - ZIP GetWeatherInformation - ID-

    1W3C (. World Wide Web Consortium)

  • 3

    . XML . XML .

    w SOAP . .

  • 4

    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 .

  • 5

    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

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

  • 6

    . .

    ASMX.CS URL-a. asmx.cs :

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    [WebService(Namespace = "http://www.moj-web-servis.org/")]

    public class MojWebServis : System.Web.Services.WebService

    {

    [WebMethod]

    public DateTime Sad()

    {

    return DateTime.Now;

    }

    [WebMethod]

    public int Saberi(int x, int y)

    {

    return x + y;

    }

    }

    , [WebService] . [WebMethod]. URL WebServis.asmx .

    SOAP SOAP -XML . ,

  • 7

    Saberi 3 8, XML:

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    3

    8

    x y - XML-a SOAP (. SOAP Envelope). SOAP - XML :

    ?

    1

    2

    3

    4

    5

    6

  • 8

    7

    8

    9

    10

    11

    SOAP . , XML .

    , 99% SOAP SOAP WSDL . , SOAP SOAP . [WebService] [WebMethod] .

    2.2

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

  • 9

    (Namespace). , Visual Studio SOAP . . . , SOAP-XML , , SOAP-XML , .

    , MojWebServis , :

    var ws = new WebServisi.MojWebServisSoapClient();

    var rezultat = ws.Saberi(3, 6);

    var datum = ws.Sad();

  • 10

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

    2.3

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

  • 11

    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.url-servera.com/Proizvod(17). URL- HTTP REST :

  • 12

    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 :

  • 13

    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 :

  • 14

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    [ServiceContract]

    public interface IProizvodRESTServis

    {

    [OperationContract]

    [WebInvoke(Method = "GET",

    UriTemplate = "/Proizvod/{id}",

    ResponseFormat = WebMessageFormat.Json)]

    string VratiDetaljeProizvoda(string id);

    }

    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 :

  • 15

    ?

    1

    2

    3

    4

    5

    6

    7

    $.ajax({

    type: "GET",

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

    success: function(odgovor){

    alert(odgovor.NazivProizvoda);

    }

    })

    REST x . x URL , HTTP . REST x .

    3.5

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