• Nie Znaleziono Wyników

XML Web Services

N/A
N/A
Protected

Academic year: 2021

Share "XML Web Services"

Copied!
9
0
0

Pełen tekst

(1)

Aplikacje sieciowe

XML Web Services

(2)

Architektura

UDDI (Web Service Broker) UDDI (Web

Service Broker)

Service Web Provider Service Web

Provider Web Service Web Service

Publish Find

Bind

Intern Internet

et

(3)

Serializacja Obiektów

• Co to jest ?

• Technologie serializacji

– XMLSerialization – SOAP

– Binarna

(4)

Protokół SOAP

• SOAP Envelope

• SOAP Header

• SOAP Body

• SOAP Fault

<soap:Envelope

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope /”>

<soap:Body>

<soap:Fault>

<faultcode>123XYZ</faultcode>

<faultstring>Server Error</faultstring>

<detail>

<bank:faultdetails xmlns:bank="urn:OnlineBank">

<message>Your account is overdrawn</message>

<errorcode>1234</errorcode>

</bank:faultdetails>

</detail>

</soap:Fault>

<soap:Envelope

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope /”>

<soap:Body>

<soap:Fault>

<faultcode>123XYZ</faultcode>

<faultstring>Server Error</faultstring>

<detail>

<bank:faultdetails xmlns:bank="urn:OnlineBank">

<message>Your account is overdrawn</message>

<errorcode>1234</errorcode>

</bank:faultdetails>

</detail>

</soap:Fault>

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

<soap:Envelope xmlns:xsi=…>

<soap:Header>

<WoodgroveAuthInfo

xmlns="http://tempuri.org/">

<Username>string</Username>

<Password>string</Password>

</WoodgroveAuthInfo>

</soap:Header>

<soap:Body>

<GetAccount

xmlns="http://tempuri.org/">

<acctID>int</acctID>

</GetAccount>

</soap:Body>

</soap:Envelope>

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

<soap:Envelope xmlns:xsi=…>

<soap:Header>

<WoodgroveAuthInfo

xmlns="http://tempuri.org/">

<Username>string</Username>

<Password>string</Password>

</WoodgroveAuthInfo>

</soap:Header>

<soap:Body>

<GetAccount

xmlns="http://tempuri.org/">

<acctID>int</acctID>

</GetAccount>

</soap:Body>

</soap:Envelope>

(5)

Dokumenty WSDL

Web Service Consumer Web Service

Consumer ServiceWeb Web

Service

wsdl [options] {URL | Path}

wsdl [options] {URL | Path}

wsdl

http://www.woodgrovebank.com/services/bank.asmx?wsdl wsdl

http://www.woodgrovebank.com/services/bank.asmx?wsdl

(6)

Klasa proxy

Web Service Consumer Web Service

Consumer ServiceWeb Web

Service

wsdl /l:VB /protocol:HttpGet /out:Bank.vb

http://www.woodgrovebank.com/services/bank.asmx?wsdl wsdl /l:VB /protocol:HttpGet /out:Bank.vb

http://www.woodgrovebank.com/services/bank.asmx?wsdl

(7)

Konfiguracja klasy Proxy

Bank theBank = new Bank();

theBank.Url =

"http://eastcoast.woodgrovebank.com/Bank.asmx";

ICredentials credentials = new NetworkCredential ("Adam", "ABarr-user", "woodgrovebank.com");

theBank.Credentials = credentials;

theBank.Timeout = 20000;

IWebProxy proxyObject = new

WebProxy("http://proxyserver:80", true);

theBank.Proxy = proxyObject;

theBank.AllowAutoRedirect = true;

Bank theBank = new Bank();

theBank.Url =

"http://eastcoast.woodgrovebank.com/Bank.asmx";

ICredentials credentials = new NetworkCredential ("Adam", "ABarr-user", "woodgrovebank.com");

theBank.Credentials = credentials;

theBank.Timeout = 20000;

IWebProxy proxyObject = new

WebProxy("http://proxyserver:80", true);

theBank.Proxy = proxyObject;

theBank.AllowAutoRedirect = true;

(8)

Tworzenie WebServisów

public class Service1 :

System.Web.Services.WebService {

...

[WebMethod]

public string HelloWorld() {

return "Hello World";

} }

public class Service1 :

System.Web.Services.WebService {

...

[WebMethod]

public string HelloWorld() {

return "Hello World";

} }

(9)

Wykorzystanie

WoodgroveOnlineBank bank = new WoodgroveOnlineBank();

Acct acct;

acct = bank.GetAccount(1);

Console.WriteLine(

"The account '{0}' has a balance of {1:C}", acct.description, acct.balance);

Console.ReadLine();

WoodgroveOnlineBank bank = new WoodgroveOnlineBank();

Acct acct;

acct = bank.GetAccount(1);

Console.WriteLine(

"The account '{0}' has a balance of {1:C}", acct.description, acct.balance);

Console.ReadLine();

class TheConsumer

{ static void Callback(IAsyncResult ar)

{ OnlineBank bank = (OnlineBank) ar.AsyncState;

Acct acct = bank.EndGetAccount(ar);

Console.WriteLine(

"The account '{0}' has a balance of {1:C}", acct.description, acct.balance);

} static void Main(string[] args)

{ OnlineBank bank = new OnlineBank();

AsyncCallback callback;

callback = new AsyncCallback(TheConsumer.Callback);

bank.BeginGetAccount("1234",callback,bank);

Console.ReadLine();

} }

class TheConsumer

{ static void Callback(IAsyncResult ar)

{ OnlineBank bank = (OnlineBank) ar.AsyncState;

Acct acct = bank.EndGetAccount(ar);

Console.WriteLine(

"The account '{0}' has a balance of {1:C}", acct.description, acct.balance);

} static void Main(string[] args)

{ OnlineBank bank = new OnlineBank();

AsyncCallback callback;

callback = new AsyncCallback(TheConsumer.Callback);

bank.BeginGetAccount("1234",callback,bank);

Console.ReadLine();

} }

Cytaty

Powiązane dokumenty

In case of multiple interpretation tasks requested from different specialized services in parallel (fig. 4), the processing may be completed even faster than a sequential

Napisz, jaką częścią zdania jest wpisany rzeczownik w każdym ze zdań.. ………

Jeśli nawet bank ekspertyz nigdy w Polsce nie powstanie jako instytucja, to dyskusja na ten temat pozwoli nam zdefiniować podstawowe pojęcia, pro- blemy

It is very innovative in its structure and content : it emphasises the practical need to learn and use statistics, and introduces advanced and modern techniques (Mixed-Effects

Lista jednokierunkowa będzie się nazywała Stopien_walu_powiazania , a kolekcja przechowująca stopnie wału Kolekcja_stopni_walu. Omówione zostaną oba sposoby, a ostatecznie

Ponieważ stopień może mieć fazę lub być bez fazy - utworzymy dwie procedury Rysuj różniące się liczbą argumentów.. Taka sytuacja to

Private Sub CzytajKolekcjęToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles CzytajKolekcjęToolStripMenuItem.Click 'Odczyt kolekcji z wielu

Diagram UML możemy wywołać klikając, w oknie Solution Explorer, prawym klawiszem myszy na pliku Class1.vb, rys. Wywołanie