Elosztott rendszerek labor — Web Service

A VIK Wikiből
A lap korábbi változatát látod, amilyen Hryghr (vitalap | szerkesztései) 2014. február 2., 21:07-kor történt szerkesztése után volt.
(eltér) ← Régebbi változat | Aktuális változat (eltér) | Újabb változat→ (eltér)
Ugrás a navigációhoz Ugrás a kereséshez

Ez az oldal a korábbi SCH wiki-ről lett áthozva. Az eredeti változata itt érhető el.

Ha úgy érzed, hogy bármilyen formázási vagy tartalmi probléma van vele, akkor kérlek javíts rajta egy rövid szerkesztéssel.

Ha nem tudod, hogyan indulj el, olvasd el a migrálási útmutatót


<style> code.pre { white-space:pre; display:block; } </style>



Web Service laborok más tárgyakból

Code-first

  • New C# Console Project: AmazonClient
  • Add Web Reference
    • URL:
      Ezen a helyen volt linkelve a(z) amazon.wsdl nevű fájl ("amazon.wsdl" link szöveggel) a régi wiki http://wiki-old.sch.bme.hu/bin/view/Infoszak/ElosztottLaborWebService oldaláról. (Ha szükséged lenne a fájlra, akkor a pontos oldalmegnevezéssel együtt küldd el a wiki
      Hiba a bélyegkép létrehozásakor: Nem lehet a bélyegképet a célhelyre menteni
      @sch.bme.hu címre a kérésedet)
(eredetileg: http://lancelot.aut.bme.hu/temp/Amazon.wsdl)
    • Web reference name: AmazonProxy
  • Double click a Web References / AmazonProxy-n

Könyvek keresése és kilistázása

using AmazonClient.AmazonProxy;   static void Main(string[] args) { AWSECommerceService service = new AWSECommerceService();   ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "Books"; request.Power = "title: .NET"; request.Sort = "salesrank"; request.ResponseGroup = new string[] { "Small" };   ItemSearchRequest[] requests = new ItemSearchRequest[] { request };   ItemSearch itemSearch = new ItemSearch(); itemSearch.AWSAccessKeyId = "079ZMCK5940PKP7WVAG2"; itemSearch.Request = requests;   ItemSearchResponse resp = service.ItemSearch(itemSearch);   Items info = resp.Items[0]; foreach (Item item in info.Item) { foreach (string name in item.ItemAttributes.Author) Console.Write(name + ", "); Console.WriteLine("\n{0}\n", item.ItemAttributes.Title); } }

Contract-first

  • New Blank Solution
  • Add New Item: PoRequest.xml (Product Order Request)
    <?xml version="1.0" encoding="utf-8"?>
    <PoRequest>
    <Product name="pen" quantity="10"/>
    <Product name="paper" quantity="1000"/>
    </PoRequest>
  • Add New Item: PoResponse.xml
    <?xml version="1.0" encoding="utf-8"?>
    <PoResponse>
    <Confirmation price="500"/>
    </PoResponse>
    • az előbbieket eljátszani a PoResponse-ra is
  • wsdl-t letölteni és hozzáadni a solution-höz:
    Ezen a helyen volt linkelve a(z) PoService.wsdl nevű fájl ("PoService.wsdl" link szöveggel) a régi wiki http://wiki-old.sch.bme.hu/bin/view/Infoszak/ElosztottLaborWebService oldaláról. (Ha szükséged lenne a fájlra, akkor a pontos oldalmegnevezéssel együtt küldd el a wiki
    Hiba a bélyegkép létrehozásakor: Nem lehet a bélyegképet a célhelyre menteni
    @sch.bme.hu címre a kérésedet)


  • Stub generálás: VS2005 Command Prompt-ból:
    wsdl /server PoService.wsdl PoRequest.xsd PoResponse.xsd
    • Generálódott egy PoServicePort.cs
  • Add New Web Site
    • ASP.NET Web Service
    • D:\User\erl\ContractFirst\Po
    • App_Code könyvtárba bemásolni a PoServicePort.cs-t
    • service.asmx / Set As Start Page
    • ...\ContractFirst\Po / Set As Startup Project, elindítani
  • Kliens oldali proxy generálás:
    wsdl PoService.wsdl PoRequest.xsd PoResponse.xsd
  • Add New Project / C# Console Application: PoClient
  • Add Reference: .NET / System.Web.Services
  • PoServicePort.cs-t átrakni a PoClient könyvtárba és felvenni a projektbe
  • PoClient / Set As Startup Project
  • A wsdl.exe inkompatibilis stubot és proxyt generált: ki kell javítani a proxyban 1 sort:
    =public PoResponse SubmitPo([System.Xml.Serialization.XmlArrayAttribute(Namespace="http://www.aut.bme.hu/PoService")] [System.Xml.Serialization.XmlArrayItemAttribute("PoRequestProduct", IsNullable=false)] PoRequestProduct[] PoRequest) {=

Po / Service.cs

using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols;   [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] [System.Web.Services.WebServiceAttribute(Namespace = "http://www.aut.bme.hu/PoService")] [System.Web.Services.WebServiceBindingAttribute(Name = "PoService", Namespace = "http://www.aut.bme.hu/PoService")] public class Service : PoServicePort { [System.Web.Services.WebMethodAttribute()] [System.Web.Services.Protocols.SoapDocumentMethodAttribute( "http://www.aut.bme.hu/PoService:submitPoIn", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)] [return: System.Xml.Serialization.XmlElementAttribute("PoResponse", Namespace = "http://www.aut.bme.hu/PoResponse")] public override PoResponse SubmitPo(PoRequestProduct[] PoRequest) { PoResponse resp = new PoResponse(); resp.Confirmation = new PoResponseConfirmation(); foreach (PoRequestProduct p in PoRequest) resp.Confirmation.price += p.quantity; return resp; } }

Az attribútumokat a PoServicePort.cs-ből kellett kimásolni.

PoClient / Program.cs

using System; using System.Collections.Generic; using System.Text;   namespace PoClient { class Program { static void Main(string[] args) { PoRequestProduct[] products = new PoRequestProduct[1]; products[0] = new PoRequestProduct(); products[0].name = "Pen"; products[0].quantity = 5; PoServicePort port = new PoServicePort(); // tálcán az ASP.NET Development Server ikon mutatja a portot // a végleges verzióban a wsdl fogja tartalmazni az url-t port.Url = "http://localhost:1529/Po/Service.asmx";   PoResponse resp = port.SubmitPo(products); Console.WriteLine(resp.Confirmation.price); } } }


-- Peti - 2006.05.05.