Top Banner
INFOSYS 290, Section 3, Fall 2005 , Web Services: Concepts, Design and Implementation Adam Blum [email protected] Lecture 4: Creating Web Services
21

INFOSYS 290, Section 3, Fall 2005 , Web Services: Concepts, Design and Implementation

Jan 08, 2016

Download

Documents

hinto

INFOSYS 290, Section 3, Fall 2005 , Web Services: Concepts, Design and Implementation. Lecture 4: Creating Web Services. Adam Blum [email protected]. Today’s Content. Creating Web Services Overview Demo Web Service Creation Raw computation Database HTML scraping XML wrapping - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

INFOSYS 290, Section 3, Fall 2005

, Web Services: Concepts, Design and Implementation

Adam [email protected]

Lecture 4: Creating Web Services

Page 2: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Today’s Content• Creating Web Services Overview• Demo Web Service Creation

– Raw computation– Database – HTML scraping– XML wrapping– SOAP web service wrapping

• Break To Set Up Environments– MindReef SOAPScope– AboveAll– Visual Studio

• Redemo of Consuming Web Services– MindReef – AboveAll– Visual Studio

• Lecture: Asynchronous Web Services

Page 3: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Creating Web Services

• Create a web service project

• Design the interface – Demoing “method-oriented interfaces” today

• Place [WebMethod] around the exposed methods

• Write your internal logic

• Test with Visual Studio and debug

Page 4: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Example Web ServicesDemonstrating Various Techniques

• Raw computation– PokerOdds

(http://www.sims.berkeley.edu/academics/courses/is290-3/f05/samples/PokerOdds)

• Database creation– ProjectTraq – Workouts

• XML wrapping– Blogs

(http://www.sims.berkeley.edu/academics/courses/is290-3/f05/samples/PokerOdds)

– SportsBetLines (http://www.sims.berkeley.edu/academics/courses/is290-3/f05/samples/PokerOdds)

• HTML/HTTP scraping– PokerOdds AnalyzeHands()

• SOAP web service wrapping– SalesForce

Page 5: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Informational Web Services

• QCUD

• Multiple records in query

• Doesn’t have to have CUD

• Richly descriptive records

• Generally comes from a persisted store

• Contrast with computation or transactional web service

Page 6: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Informational Web Service Examples

• Sales accounts, contacts, tasks, opportunities

• Project bugs

• Helpdesk, customer support items

• Blog entries

• Newsfeeds

Page 7: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Consuming Web Services

• Ad hoc tools and management systems– E.g. MindReef SOAPScope

• Forms design environments– E.g. AboveAll Studio

• Third generation traditional programming environments– E.g. Visual Studio.NET 2005

Page 8: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Asynchronous Web Services

Page 9: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Why Asynchronous Web Services?

• Speed– Due to overhead of XML and http XML web services

can be SLOW• Unpredictability

– Your app may be invoking a web service that itself is slow, unreliably available or involves a human in the process

• Size– Moving to larger coarsegrained documents and less

frequent chatty method calls can introduce more overhead

Blocking on downstream services creates instant bottlenecks in your application

Page 10: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Creating Asynchronous Web Services

• Write “begin” and “end” methods versus single invocation methods

• VisualStudio.NET generates:– public System.IAsyncResult

BeginValidateEmailAddress(string emailAddress, System.AsyncCallback callback, object asyncState) {

– return this.BeginInvoke("ValidateEmailAddress", new object[] {emailAddress}, callback, asyncState);

– }

– public CheckEmailResult EndValidateEmailAddress(System.IsyncResult asyncResult) {

– object[] results = this.EndInvoke(asyncResult);– return ((CheckEmailResult)(results[0]));– }

Page 11: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Invoking Asynchronous Web Services

• Polling

• Blocking

• Callbacks

Page 12: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Polling// polling versionprivate void Command1_Click(object sender, System.EventArgs e){

emailvalidatorproxy=new Einsteinware.EmailServices();• int start=DateTime.Now.Second;• IAsyncResult

ar=emailvalidatorproxy.BeginValidateEmailAddress(TextBox1.Text,null,null);

• while (!ar.IsCompleted){– //do stuff

• }

• switch(emailvalidatorproxy.EndValidateEmailAddress(ar)){– case Einsteinware.CheckEmailResult.Valid:

• Label1.Text="Valid";• break;

– default:• Label1.Text="Invalid";• break;

• }}

Page 13: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Blocking• private void Command1_Click(object sender, System.EventArgs e)• {• emailvalidatorproxy=new Einsteinware.EmailServices();

• IAsyncResult ar=emailvalidatorproxy.BeginValidateEmailAddress(TextBox1.Text,cb,emailvalidatorproxy);

// do lots of stuff

• ar.AsyncWaitHandle.WaitOne();

• switch(response)• {• case Einsteinware.CheckEmailResult.Valid:• Label1.Text="Valid";• break;• default:• Label1.Text="Invalid";

}• }

Page 14: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

WaitHandle Object

• WaitOne– Waits for this one handle

• WaitAny– Static method which takes array of

WaitHandles, returns when any have completed

• WaitAll– Returns when all have completed

Page 15: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Invoking with a Callback// callback versionprivate void Command1_Click(object sender,

System.EventArgs e){

emailvalidatorproxy=new Einsteinware.EmailServices();// instantiate the AsyncCallback delegate AsyncCallback cb = new AsyncCallback(EmailvalidatorCallback);int start=DateTime.Now;IAsyncResult ar=

emailvalidatorproxy.BeginValidateEmailAddress(TextBox1.Text,cb,null);

Label1.Text=Label1.Text + "(" + System.Convert.ToString( DateTime.Now.CompareTo(start) ")";

}

Page 16: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

The Callback Itself• public delegate void MyDelegate(Label l,String s);

• private void EmailvalidatorCallback(System.IAsyncResult ar)• {• CheckEmailResult

response=emailvalidatorproxy.EndValidateEmailAddress(ar);• switch(response)• {• case CheckEmailResult.Valid:• message="Valid";• break;• …• }• responseLabel.Invoke(• new MyDelegate(DisplayResponse),new object[]{label1,message});

• }• private void DisplayResponse(Label label,String message)• {• label.Text=message;• Form1.ActiveForm.Refresh();• }

Remember: callbacks are on a separate thread and need a way to communicateback to the main thread to display…hence delegates

Page 17: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Using the Async State Object• // using async state to handle two label objects• private void button1_Click(object sender, System.EventArgs e)• {• label1.Text="";label2.Text="";• emailvalidatorproxy=new Einsteinware.EmailServices();• IAsyncResult ar=

emailvalidatorproxy.BeginValidateEmailAddress(

textBox1.Text,new AsyncCallback(EmailvalidatorCallback),label1);

• IAsyncResult ar2=emailvalidatorproxy.BeginValidateEmailAddress(textBox1.Text,new AsyncCallback(EmailvalidatorCallback),label2);

• }

Page 18: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Callback Using the Async State Object

• private void EmailvalidatorCallback(System.IAsyncResult ar)• {

– CheckEmailResult response=emailvalidatorproxy.EndValidateEmailAddress(ar);

– String message="";– switch(response)– {– case EinsteinwareCheckEmailResult.Valid:

• message="Valid“;break;

– case CheckEmailResult.InvalidUser:• message="Invalid user";• break;• …

– }– Label responseLabel = (Label)ar.AsyncState;– responseLabel.Invoke(new MyDelegate(DisplayResponse) ,new

object[]{responseLabel,message});• }

Page 19: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

Course Project• Goal

– Build “web service consuming” client applications from desktops and mobile devices• Requirements

– Use an “informational” web service• Has QCUD (Query, Create, Update and Delete operations)• Query returns MULTIPLE records

– Consume web service from AboveAll or Visual Studio for desktop– Consume WS from GoodAccess Web Services or Visual Studio from mobile device– Optionally write or enhance a backend web service

• Possibly as a “proxy web service” layer on top of original web service• Only if previous steps are achieved

– Demo to class– Write up as three page paper including: architecture and UI design

• Team size– Two people per project

• Proposal– Due today, will accept later

Page 20: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

References

• Specs– SOAP Specification, http://www.w3.org/TR/soap/– WSDL Specification, http://www.w3.org/TR/wsdl– UDDI Specification,

http://www.uddi.org/specification.html

• Tools– Visual Studio, http://microsoft.com/vstudio– Microsoft Web Services Enhancements

• http://msdn.microsoft.com/webservices/building/wse/default.aspx

Page 21: INFOSYS 290, Section 3, Fall 2005 ,  Web Services: Concepts, Design and Implementation

How To Reach Me

[email protected]

• 408-396-5490

• Office hours Thursday at 4pm

[email protected]