0% found this document useful (0 votes)
19 views20 pages

Developing Web Applications Using Microsoft Visual Studio 2008

The document provides an overview of creating and consuming XML web services in Microsoft Visual Studio 2008. It discusses calling an existing XML web service, creating a new XML web service, and includes a lab scenario for building a dental services web application that utilizes XML web services.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views20 pages

Developing Web Applications Using Microsoft Visual Studio 2008

The document provides an overview of creating and consuming XML web services in Microsoft Visual Studio 2008. It discusses calling an existing XML web service, creating a new XML web service, and includes a lab scenario for building a dental services web application that utilizes XML web services.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Developing Web

Applications Using
Microsoft® Visual
Studio® 2008
Module 13: Consuming and Creating XML Web Services
• Overview of XML Web Services

• Calling an XML Web Service

• Creating an XML Web Service


Lesson: Overview of XML Web Services
• What Is an XML Web Service?

• Why Use XML Web Services?

• Finding an XML Web Service

• Multimedia: XML Web Service Execution Model


What Is an XML Web Service?
• Contains programmable logic accessible by standard Web
protocols
• Enables applications to send and receive information
across the Internet
 Language, protocol, and platform independent
 Stateless architecture
 Asynchronous or synchronous

• Based on a W3C standard that constantly evolves


Why Use XML Web Services?

Travel Site

Pick your Redmond Weather


destination: XML Web Service
Internet
The weather
forecast is:
Rain

The exchange rate is:


$1.56 Exchange Rate
XML Web Service
We can fly you
there for only:

$1,999.98 Airfare
XML Web Service

Airfare
Database
Finding an XML Web Service

Publish the XML Web


11 service URL and description

22 Discover the XML Web service


UDDI

33 Locate the XML Web


service URL Web Form 22
11
44 Read the .wsdl description .disco
33
55 Bind the XML Web service to 44 .wsdl
the proxy

55 66 Web Service
66 Call the XML Web service Proxy
from the Web Form by Proxy
Multimedia: XML Web Service Execution Model
Lesson: Calling an XML Web Service
• Calling an XML Web Service by Using HTTP

• What Is a Proxy?

• Steps for Calling an XML Web Service

• XML Web Service Error Handling

• Demonstration: Testing the Availability of an XML Web


Service
Calling an XML Web Service by Using HTTP

Browse to the XML


11 Web service URL

22 Select an XML Web


service method

33 Call the XML Web


service method

44 View the XML


response
What Is a Proxy?
• Appears the same as the original class but does not
contain application logic
• Uses SOAP to interact with the XML Web service

• Created from the Web Service Description Language


file (WSDL)
• Adds members to manage interactions with the XML
Web service and support asynchronous calls

Internet
Web
Form
XML Web
Service

SOAP
Proxy
Steps for Calling an XML Web Service

11 Create a Web reference for the XML Web service

22 Create an instance of the XML Web service

33 Call the Web methods of the XML Web service

44 Build the ASP.NET Web application

[Visual C#]
private void Button1_Click(object sender, System.EventArgs e)
{ localhost.Service1 ProxyGetStocks = new
localhost.Service1();
lblResults.Text = ProxyGetStocks.GetRating("Contoso");
}

[Visual Basic]
Sub Button1_Click(s As Object, e As EventArgs) Handles _
Button1.Click
Dim ProxyGetStocks As New localhost.Service1()
lblResults.Text = ProxyGetStocks.GetRating("Contoso")
End Sub
XML Web Service Error Handling
• Service unavailable

GetStocks.StockWebRef.Service1 ProxyGetStocks =
new GetStocks.StockWebRef.Service1();
ProxyGetStocks.Timeout = 10000;
try
{
lblMessage.Text =
ProxyGetStocks.GetRating(TextBox1.Text);
}
catch (Exception err)
{
lblMessage.Text = err.Message;
}

• SOAP exceptions from XML Web services


Demonstration: Testing the Availability of an XML
Web Service
• Set a timeout error handling Try…Catch statement

• Slow the Web service

• Test the exception


Lesson: Creating an XML Web Service
• Steps to Create an XML Web Service

• XML Web Service Code


Steps to Create an XML Web Service

11 Create a new XML Web service project

22 Declare the WebMethod functions

33 Build the XML Web service project

44 Test with a browser


XML Web Service Code
• .asmx page
 Contains file type information and a directive to the
code-behind page

• Code-behind page
[Visual C#]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public type function1()
{
//function here
}
}

[Visual Basic]
Class Service1
<WebMethod()> Public Function function1() As type
'function_here
End Function
End Class
Lab: Consuming and Creating XML Web Services
• Exercise 1: Creating the Dentist XML Web Service and the
GetAllDentists XML Web Service Method
• Exercise 2: Creating the GetDentistsByPostalCode XML
Web Service Method
• Exercise 3: Consuming the GetAllDentists XML Web
Service Method
• Exercise 4: Consuming the GetDentistsByPostalCode XML
Web Service Method

Logon information

Virtual machine 2310C-LON-DEV-13


User name Student
Password Pa$$w0rd

Estimated time: 45 minutes


Lab Scenario

Master Page
Logon Page benefitsMaster.master
login.aspx
Benefits Lab Web
Home Page Application
ASPState
Default.aspx Page Header
header.ascx
Menu Component
Registration Benefits.cs or Benefits.vb
register.aspx TempDB
Web.
config

Life Insurance Retirement Medical Dentists


life.aspx retirement.aspx medical.aspx dental.aspx

Prospectus
prospectus.aspx Doctors User Control XML Web
LINQ to SQL doctors.aspx nameDate.ascx Service
Classes DentalService1.asmx
Doctors.dbml

Dentists
Doctors
XML Files
Lab Review
Review Questions
• When you test a Web service, where does the description
page come from?
• What is the effect if you change the default namespace of
a Web service?
• What must you do in the Benefits Web site before you can
consume the methods in the DentalService Web service?
Module Review and Takeaways
• Review Questions

• Common Issues and Troubleshooting Tips

• Real-World Issues and Scenarios

You might also like