Consuming Web Services

When you add a Web reference, Visual Studio .Net is actually creating a wrapper class that encapsulates all of the SOAP code. This section talks about doing this. Figure 14.7 shows how to add a Web Reference, Figure 14.8 shows the Web Reference in the Solution Explorer Window, and Figure 14.9 shows using a Web Reference from an ASP.NET application, and Figure 14.10 shows using a Web Reference from a stand-alone application.

 private void Page_Load(object sender, System.EventArgs {   if( !IsPostBack )   {     com.dotnet_networking.www.Service1 svc =       new com.dotnet_networking.www.Service1();     string[] Names = svc.GetSalesForce();     NameList.DataSource = Names;     NameList.DataBind();   } } private void Button1_Click(object sender, System.EventArgs {   com.dotnet_networking.www.Service1 svc =     new com.dotnet_networking.www.Service1();   double dCommissionRate =     svc.GetCommissionRate( NameList.SelectedItem.Value );   CommissionRate.Text = "Commission Rate: " +     Convert.ToString( dCommissionRate ) + "%"; } private void button1_Click(object sender, System.EventArgs {   com.dotnet_networking.www.Service1 svc =     new com.dotnet_networking.www.Service1();   PharmInfo.Text = svc.GetPharm( NDC.Text ); } 
Figure 14.7. When You Add a Web Reference, the Web Service Will Return a WSDL Contract.

graphics/14fig07.jpg

Figure 14.8. The Web Reference Shows Up in the Solution Explorer Window.

graphics/14fig08.jpg

Figure 14.9. This Application Shows How Easy It Is to Use a Web Service from an Application.

graphics/14fig09.jpg

Figure 14.10. This C# Windows Application Uses a Web Service Easily.

graphics/14fig10.jpg



ASP. NET Solutions - 24 Case Studies. Best Practices for Developers
ASP. NET Solutions - 24 Case Studies. Best Practices for Developers
ISBN: 321159659
EAN: N/A
Year: 2003
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net