Developing Web Applications Using Microsoft Visual Studio 2008
Developing Web Applications Using Microsoft Visual Studio 2008
Applications Using
Microsoft® Visual
Studio® 2008
Module 13: Consuming and Creating XML Web Services
• Overview of XML Web Services
Travel Site
$1,999.98 Airfare
XML Web Service
Airfare
Database
Finding an XML Web Service
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?
Internet
Web
Form
XML Web
Service
SOAP
Proxy
Steps for Calling an XML Web Service
[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;
}
• 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
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
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