Visual CSharp 2005 Express Edition (2006) [eng]
.pdf
Chapter 15
com.capescience.live.WeatherReport wsReport =
wsWeather.getWeatherReport(this.txtAirportToLocate.Text);
Once you have the WeatherReport, as referenced by wsReport, you can then access the various classes representing the various types of information:
lblStation.Text = wsReport.station.@string; lblSky.Text = wsReport.sky.@string; lblVisibility.Text = wsReport.visibility.@string; lblWind.Text = wsReport.wind.@string; lblTemperature.Text = wsReport.temperature.@string;
Interestingly, to get the complete string of information, you will use the string property of the particular class you are retrieving. However, since the word string is a key word in C#, you will have to tell C# to use the literal value of “string” instead of the keyword meaning, in this case the property, not the keyword. To specify this, you use the @ symbol, as you do when you want to use the “\” as a backslash instead of as a control character, such as in \n the newline command.
Try It Out |
Creating the Form and Code for the GlobalWeather Web Service |
Continuing to work with the form created in the chapter, you will add the form and code necessary to call the methods in the GlobalWeather Web service:
1.Select Project Add Windows Form . . . , and name it as desired. For the purpose of this example, I named it frmGetWeather.cs.
2.Add a Label (Text property set to “Airport to Locate”), TextBox (Name property set to txtAirportToLocate), and Button (Name property set to btnGetWeather) control as shown in Figure 15-20.
Figure 15-20
274
Using Web Services from Your C# Application
3.For each of the five pieces of information, also displayed in Figure 15-20, add labels down the left side of the form, which the Text properties set to “Station Info,” “Sky,” “Visibility,” “Wind,” and “Temperature.”
4.On the right side of the form you will add five additional Label controls, corresponding to the label added in Step 3, with the Name property: lblStation, lblSky, lblVisibility, lblWind, and lblTemperature.
5.Set the AutoSize property on each of the Label controls added in Step 4 to False. This will allow you to adjust the height and width of the controls.
6.Double-click btnGetWeather. The code file for the form opens, and the new routine is created for the Click event of btnGetWeather, as shown here:
private void btnGetWeather_Click(object sender, EventArgs e)
{
}
7.Type the following code inside the code block for btnGetWeather_Click routine.
com.capescience.live.GlobalWeather wsWeather =
new com.capescience.live.GlobalWeather();
com.capescience.live.WeatherReport wsReport = wsWeather.getWeatherReport(this.txtAirportToLocate.Text);
lblStation.Text = wsReport.station.@string; lblSky.Text = wsReport.sky.@string; lblVisibility.Text = wsReport.visibility.@string; lblWind.Text = wsReport.wind.@string; lblTemperature.Text = wsReport.temperature.@string;
The final routine looks as follows:
private void btnGetWeather_Click(object sender, EventArgs e)
{
com.capescience.live.GlobalWeather wsWeather =
new com.capescience.live.GlobalWeather();
com.capescience.live.WeatherReport wsReport = wsWeather.getWeatherReport(this.txtAirportToLocate.Text);
lblStation.Text = wsReport.station.@string; lblSky.Text = wsReport.sky.@string; lblVisibility.Text = wsReport.visibility.@string; lblWind.Text = wsReport.wind.@string; lblTemperature.Text = wsReport.temperature.@string;
}
8.Press F5 to build and execute the application. The form opens waiting for you to enter an airport code for which to retrieve weather information.
9.Type an airport code such as SEA or LAX.
10.Click the btnGetWeather button. The information is displayed.
275
Chapter 15
For a list of other airport codes, you can go back to the GlobalWeather Web service Web page, shown in Figure 15-13.
Note that if you were using this for a real application, you really ought to check for a null return value, which you get for a nonexistent airport code. Without checking, you get a null-reference exception.
Summar y
The limitations on how data is transmitted and received in a convenient yet secured manner has been an issue since information started being traded among companies and locations. The latest method, Web Services, provides both convenience and security for developers in a way like never before.
When companies provide Web services, developers can use various languages for the consumption of the Web service, provided the language supports it. In C# Express and the other Visual Studio products, adding Web services to your applications is as simple as adding a Web reference, declaring objects using the classes provided by the Web service, and utilizing the properties and methods of those types provided by the Web service.
This chapter showed you how to locate Web services both on the Web and using C# Express. It then went on to discuss how to create Web references and use them inside your applications, giving examples of retrieving stock quotes and weather information.
Exercises
1.What does UDDI stand for?
2.What are the four sections of Web services infrastructure?
3.Name two of the ways to locate Web services that you can use in your applications.
4.What utility enables you to discover the various classes, methods, and properties once a Web reference has been established for a Web service?
276
16
Publishing Your Application
and Next Steps
No book on development is complete nowadays without discussing how to publish your applications, also called deployment. When you publish or deploy your application, you are making it available for other people’s use. In the past it was a big deal to create and maintain the files to distribute applications. I remember in the early Microsoft Access days when I distributed an application, it took 10 floppy disks to hold all the parts of the program.
What you want to do with your final application will determine how you want to publish it.
This chapter wraps up everything I have been talking about with regard to C# Express and what you can do with it. In this chapter, you will:
Find out how to deploy your application.
Look at some of the next steps you want to take, such as developing C# Web applications.
Read about some of the specific features of Visual Web Developer Express.
Take a look at some third-party tools.
Publishing Your C# Express
Applications?
Unfortunately, no deployment tools are included in the Express products. With the full versions of Visual Studio products project setup templates are included to help your deploy (distribute) your applications. If you want to give your application to someone to use, then you will need to give them all the files in the Bin\Release folder (or Bin\Debug) located under your project folder.
Chapter 16
The person using your application will then need to have the .NET Framework 2.0 installed on their machine. Generally, the idea behind using the Express products is to get you going in development and then have you move on if you are going to be distributing the applications you create.
Where to Go from Here?
You have learned so much in this book. I have tried to put you on the path to really enjoying what you are doing with C# Express and to understand the power you have available. These next sections take a look at what are the next steps to working with C# besides just getting as much experience as possible with the product.
Developing for the Web: Visual Web Developer 2005
Express Edition
As mentioned, not only can C# be used in Windows forms as has been shown throughout the book but also for Web development. Along with the other .NET products, Microsoft has created a Web development environment called ASP.NET. There are a couple of ways to get into ASP.NET:
Upgrade to the full version of Visual Studio .NET and use ASP.NET, discussed in the section entitled “Moving Up to Visual Studio .NET,” found later in this chapter.
Download Visual Web Developer 2005 Express Edition. Like C# Express, this product has been created to introduce students, hobbyists, and other new developers to the world of programming, in this case programming on the Internet.
Of the two alternatives, the later is the cheapest way to get going in ASP.NET. Built on ASP 2.0, Visual Web Developer 2005 Express Edition (VWD) gives developers tools they need to build Web applications. Much like C# Express, the Web Developer 2003 Express includes the following:
Visual designers. Let you drag and drop controls onto Web forms, just as you would Windows forms.
Code editor. Makes writing HTML quicker and more conveniently than ever and includes that great product with the silly name of IntelliSense. HTML tags, including methods and properties, are listed as you write your code.
Microsoft SQL Server 2005 Express. Integrated using the Database Explorer, similar if not the same data controls are included so that you can drag and drop them onto your Web forms with little or no coding.
Starter kits. These are included to help you get going, including the Personal Web Starter Kit.
When using the full version of ASP.NET, you can create your own XML Web Services, as discussed in Chapter 15.
In addition to the similarities with C# Express, VWD includes the capability of installing a personal Web server not requiring IIS.
One way to get started using VWD is to buy Wrox’s ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter Kit. Another is to download a copy as shown in the next Try It Out.
278
Publishing Your Application and Next Steps
Try It Out |
Downloading and Installing Visual Web Developer |
|
2005 Express Edition |
Using your favorite browser:
1.Type http://lab.msdn.microsoft.com/express/vwd/default.aspx. You are taken to the home page for VWD, as shown in Figure 16-1.
Figure 16-1
2.Click Download now.
3.After filling out the survey, click Download. The standard Run, Save Internet dialog box appears.
4.Click Run. The Setup program starts, as shown in Figure 16-2.
279
Chapter 16
Figure 16-2
5.Click Next. The next page on the setup form asks which destination folder you want to install VWD into, as shown in Figure 16-3.
Figure 16-3
6.Click Install. The setup program downloads and installs VWD.
280
Publishing Your Application and Next Steps
Moving Up to Visual Studio .NET
The other possibility is to move up to the big time and make an investment in Visual Studio .NET 2005. Everything you learned in this book about C# and the tools for development apply to the full-blown version. You will find the IDE almost exactly the same but with additional tools.
With Visual Studio .NET you can use ASP.NET 2.0 to create Web sites as well as Web services. You can take your applications and use them in Visual Studio .NET 2005. You will also notice quite a few more templates, allowing you to create additional types of applications such as Windows service applications and installation packages.
Using Third Party Tools and Other Sources of Information
A number of third-party tools and libraries are available for your use. Here are just a few of the companies that sell tools, and the uses you can put them to:
FMS Inc. — Total .NET Developer Suite. These tools provide various services for everything from analyzing your .NET applications to making best-practice and performance recommendations. The tool I like the best is Total .NET Source Book. This tool is a library of code that you can use in your applications. One of the coolest features is that it takes advantage of Web services to retrieve updates and new code for you.
This tool is great for checking out how to perform various tasks and use code already created for you. Find out more about it at www.fmsinc.com.
dtSearch — Full Text Retrieval. This tool is an engine that helps you perform full text searches on various kinds of documents such as Word documents, PDFs, HTML, and even other databases such as SQL Server and Access. Included is an engine that has fully managed code driving it, with classes using properties and methods to help make life simpler. You can find the Web site for dtSearch at www.dtsearch.com.
dtSearch is a more specialized tool that you may never have a need for, but it is so powerful that it is worthwhile to mention.
www.dotnetjunkies.com. This Web site is created specially for .NET developers. There are various authors, including myself, who write for the site because we love the subject matter. You can check out my column called “The First Hit,” which is specifically for new .NET developers such as yourself.
Note that I get no monetary recompense from either of the companies mentioned here. Their products just rock.
Summar y
Throughout the book, you have seen various ways to make C# perform tasks the way you need it
to. Everything from simply creating a form, to utilizing Web services over the Net, to publishing your applications was covered. And it only gets better from here on out. As you are working with C# and C# Express, you will get more and more comfortable with using the various tools.
281
Chapter 16
In this chapter, you saw how you could publish your C# applications in a number of different ways, either on a CD, the Web, or on a local network. You also saw some of the various tools available out there for your use in your applications. These tools can be located using the Internet and are for different purposes.
Exercises
1.What is it called when your application is ready to be distributed?
2.What product is used for Web development both in Visual Studio .NET 2005 and Visual Web Development Express?
3.What is the name of my column on DotNetJunkies.com?
282
A
Answers to Exercises
Chapter 1
Exercises
1.What is the difference between C# and Visual C# Express?
2.What are the four sections on the C# Express start page?
3.What does the acronym IDE stand for?
4.Name three of the tools available in the C# Express IDE.
5.What is the difference between a console application and Windows application?
Answers
1.C# is a programming language. Visual C# Express is a development environment.
2.Open an Existing Project, Getting Started, Visual C# Express Headlines, and MSDN: Visual C#.
3.Integrated Development Environment.
4.Solution Explorer, Database Explorer, and Task List.
5.Console applications generally are utilities that are run without user intervention, whereas Windows applications are interactive programs for users with forms.
Chapter 2
Exercises
1.What is the difference between hardware and software?
2.What are the differences between compiled and interpreted languages?
3.Name the three levels of Windows programming mentioned in this chapter.
4.What are dynamic-linked libraries used for?
