Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Code the ws_SaveSignatureCompletedevent handler as follows:

void ws_SaveSignatureCompleted( object sender,

Signature.ServiceReference1.SaveSignatureCompletedEventArgs e) {

txtStatus.Text = "Signature sent to WS!";

}

In Page.xaml.cs, code the Loadbutton as follows:

//---Load button---

void btnLoad_MouseLeftButtonDown(

object sender, MouseButtonEventArgs e) {

try {

ServiceReference1.WebServiceSoapClient ws = new

Signature.ServiceReference1.WebServiceSoapClient();

//---wire up the event handler when the web service

// returns---

ws.GetSignatureCompleted +=

new EventHandler(ws_GetSignatureCompleted);

//---calls the web service method---

ws.GetSignatureAsync();

} catch (Exception ex) {

txtStatus.Text = ex.ToString();

}

}

Here, you call the Web service to retrieve the saved signature. When the Web Service call returns, the ws_GetSignatureCompletedevent handler will be called.

Code the ws_GetSignatureCompletedevent handler as follows:

void ws_GetSignatureCompleted( object sender,

Signature.ServiceReference1.GetSignatureCompletedEventArgs e) {

txtStatus.Text = "Signature loaded from WS!";

DrawSignature(e.Result);

}

Save the Signatureproject. In Solution Explorer, right-click on the SignatureWebSiteproject and select Add Silverlight Link (see Figure 19-77).

Figure 1977 This causes Visual Studio 2008 to copy the relevant files from the - фото 447

Figure 19-77

This causes Visual Studio 2008 to copy the relevant files from the Silverlight project onto the current project. Use the default values populated and click Add (see Figure 19-78).

Figure 1978 Notice that a new folder named ClientBin containing the - фото 448

Figure 19-78

Notice that a new folder named ClientBin, containing the Signature.xapfile, is added to the project (see Figure 19-79).

Figure 1979 In Solution Explorer rightclick the SignatureWebSiteproject and - фото 449

Figure 19-79

In Solution Explorer, right-click the SignatureWebSiteproject and select Set as Startup Project (see Figure 19-80).

Figure 1980 Select SignatureTestPageaspx and press F5 to test the project - фото 450

Figure 19-80

Select SignatureTestPage.aspx, and press F5 to test the project. You can now save the signature to the Web Service as well as load the saved signature from the Web Service (see Figure 19-81).

Figure 1981 Summary This chapter has demonstrated how you can use - фото 451

Figure 19-81

Summary

This chapter has demonstrated how you can use Silverlight to build Rich Interactive Applications (RIAs). At the time of writing, there are two versions of Silverlight — 1.0 and 2 — the key difference being the integration of the .NET Framework in Silverlight 2. To build the user interface of a Silverlight application, you can use the Microsoft Expression suite of applications, while the coding can be done using Visual Studio 2008.

Chapter 20

Windows Communication Foundation

Windows Communication Foundation (WCF) is Microsoft's unified programming model for building service oriented applications (SOA). Parts of a service-oriented application can be exposed as a service that other applications can access.

WCF is a big topic, and it cannot be fully covered in a single chapter. However, this chapter provides a quick introduction to this new technology and shows how it addresses some of the limitations of today's technology. While most books and conference focused heavily on the theory behind WCF, this chapter shows you how to build WCF services and then explains the theory behind them.

In short, this chapter explores:

□ How traditional ASMX Web Services differ from WCF

□ The ABCs of WCF

□ Building different types of WCF services

What Is WCF?

To understand the rationale behind WCF, it is important to understand the offerings that are available today. In previous versions of Visual Studio (Visual Studio 2005 and Visual Studio .NET 2003), you use the ASP.NET application model to you create ASMX XML Web Services that expose functionalities to clients who want to use them.

ASMX Web Services are still supported in Visual Studio 2008 for backward compatibility, but going forward Microsoft recommends that developers use WCF when building services.

To compare WCF and ASMX Web Services, let's first use Visual Studio 2008 to create a new ASP.NET Web Service Application project. Name the project StocksWS.

Populate the default Service1.asmx.csfile as follows:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Linq;

namespace StocksWS {

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]

public class Service1 : System.Web.Services.WebService {

[WebMethod]

public float GetStockPrice(string symbol) {

switch (symbol) {

case "MSFT":

return 29.91f;

case "AAPL":

return 180.21f;

case "YHOO":

return 23.93f;

default:

return 0;

}

}

}

}

This Web Service contains a web method to let users query the price of a stock. For simplicity, you will hardcode the stock prices of a few stocks.

To host this Web Service, you need to publish this project to a web server (IIS, for instance), or use the ASP.NET Web Development server that ships with Visual Studio. Figure 20-1 shows the ASP.NET Web Development Server hosting the service after you press F5.

Figure 201 For a client to use this Web Service you need to add a web - фото 452

Figure 20-1

For a client to use this Web Service, you need to add a web reference. So add a Windows Forms Application project to the current solution to consume this service. Name the project StockPriceChecker.

Populate the default Form1with the controls shown in Figure 20-2.

Figure 202 To add a reference to the Web Service rightclick the project name - фото 453

Figure 20-2

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x