Aplikacje sieciowe
XML Web Services
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
Serializacja Obiektów
• Co to jest ?
• Technologie serializacji
– XMLSerialization – SOAP
– Binarna
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>
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
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
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;
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";
} }
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();
} }