Adobe
製品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
その他の製品一覧
ソリューション
デジタルマーケティング
デジタルメディア
教育
金融機関
Web Experience Management
その他のソリューション
ラーニング サポート ダウンロード 会社情報
ご購入
アドビストア 安心のサポート& サービス
アカデミックストア 学生、教職員、個人向け
アドビライセンスストア 中小企業向け
ボリュームライセンスについて 企業、教育機関、官公庁向け
販売パートナー
キャンペーン情報
検索
 
情報 サインイン
ようこそ、 さん カート 注文状況 マイアカウント
マイアカウント
注文状況
アカウント情報の変更
コミュニケーションの設定を変更
サインアウト
サインインの目的 お客様のアカウントや体験版ダウンロード、製品の拡張機能、コミュニティエリアへのアクセスなどを管理するため
Adobe
製品 セクション ご購入   検索  
ソリューション 会社情報
サポート ラーニング
サインイン サインアウト 注文状況 マイアカウント
先行予約の提供開始予定日Date. 商品が発送されるまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。 先行予約の提供開始予定日Date. ダウンロードの準備が整うまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。
個数:
ご購入には学生・教職員個人版の購入資格の確認が必要です。
小計
カートの中身を見る
Adobe Developer Connection / Flexデベロッパーセンター /

Using Flash Builder 4 to build a Flex application that consumes a .NET-based web service written in C#

著者 Nishad Musthafa

Nishad Musthafa
  • nishadmusthafa.wordpress.com

Created

19 July 2010

ページ ツール

Facebookでシェア
Twitterでツイート
LinkedInでシェア
ブックマーク
印刷

タグ

必要条件

この記事に必要な予備知識

Some experience with web programming using the .NET platform and C#, as well as the ability to set up and use databases with SQL Server is required. Prior experience with Flex will be helpful.

ユーザーレベル

初級

必要な製品

  • Flash Builder 4 (Download trial)

サンプルファイル

  • flashbuilder_webservice_dotnet.zip (299 KB)

This article describes how to use the data-centric development features of Flash Builder 4 to build a Flex application that accesses an SQL database created in Microsoft Visual Studio via a .NET-based web service. Web services are commonly used as a mechanism for data delivery on the Internet, and the .NET platform is widely used to implement web services. By following the steps in this tutorial, you will see how easy it is to retrieve data from a web service in a Flex application without writing any code.

Exposing the database through a .NET-based web service

The example database for this tutorial is for an imaginary courier company that has stored the locations of its offices in the form of a table (named Centre) with the following columns and data types (see Figure 1):

  • Name - nchar(10)
  • Longitude - numeric(9,6)
  • Latitude - numeric(9,6)
Schema for the Centre database table
Figure 1. Schema for the Centre database table

Creating the web service

To access the data from the Centre table, you can use the sample files included with this tutorial, which implement a simple web service in C#. The code consists of three files:

  • Centre.cs – This class is used to represent each tuple of the Centre table of the database.
  • Service.cs – This implements the System.Web.Services.WebService class and provides a set services (in the form of two function calls), which can be invoked from Flex. The getCentres() function retrieves all the tuples in the database and returns them as an array of Centre objects. The getCentreNames() function retrieves the list of CentreName attributes alone and returns them as an array of strings. The functions connect to the database using the System.Data.SqlClient namespace.
  • Service.asmx – This is the exposed web page that will run on the server. There is nothing in the code but a reference to the web service class Service.cs. You invoke this page to access the services.

Exposing the web service with WSDL

Before you can start using the web service functions from a Flex client, you need to know a little bit about Web Service Description Language (WSDL). WSDL is a standard XML-based language used to describe or model web services.

When you create a web services in Visual Studio, the WSDL is automatically generated. If the web service is deployed on a server, then the path of the WSDL is in the following format unless specified otherwise by the user:

http://{serverpath}/{context of the web application}/{Name of the services file- for example, services.asmx}?WSDL

While debugging in Visual Studio the default WSDL path for Service.asmx in the project named CentreServices is:

http://localhost:4682/CentreServices/Service.asmx?WSDL

This WSDL path will be used in Flash Builder 4 to connect to the service.

You can use the Database.mdf file, which is included among this tutorial’s sample files, as the SQL Server database.

The code in Service.cs includes two path references that you’ll need to change. Search for AttachDbFilename=/*ENTER PATH OF THE DB HERE*/ in the file and edit the two instances as necessary for your configuration. Refer to comments within the file to format the path properly.

Defining the web service in Flash Builder 4

After setting up the web service code and the database on your local server, start Flash Builder 4 and follow these steps to define the web service:

  1. Choose File > New > Flex Project to create a new project.
  2. Type a project name (for example, DotNetWebService).
  3. For the Application Type, select Web (Runs In Flash Player).
  4. For the Application Server Type, select None/Other.
  5. Click Finish.
  6. Choose Window > Data/Services to open the Data/Services view.
  7. In the Data/Services view, click Connect To Data/Service.
  8. In the Select Service Type dialog box, select Web Service (see Figure 2).
Connecting to the web service
Figure 2. Connecting to the web service
  1. In the Specify A WSDL URL To Introspect dialog box, type the WSDL path in the WSDL URI text box (see Figure 3).

    The Service Name, Service Package, and Data Type Package are filled in automatically by Flash Builder 4. Since the name of the ASMX file is Service.asmx, Flash Builder 4 has given the Service Name the same value by default.

  2. Type CentreService as the Service Name to give your service a more descriptive name.
Entering the WSDL URI
Figure 3. Entering the WSDL URI
  1. Click Next.

    Flash Builder 4 will introspect the WSDL file and present a list of services, ports, and operations supported by the service.

  2. Make sure the two functions, getCentres() and getCentreNames() are selected.
  3. Click Finish.

In the Data/Services view you’ll see a list of the different operations and data types that were identified for the service (see Figure 4).

The Data/Services view
Figure 4. The Data/Services view

In just a few simple steps, you defined the .NET-based web service. Flash Builder 4 introspected the service, automatically generated value objects, and assigned the correct return types to the service’s operations.

Binding the data to the UI using data-centric development

Now that you’ve set up the service in Flash Builder 4, you’re ready to connect it to the user interface of your Flex application:

  1. In Flash Builder 4, switch to Design view.
  2. Drag a List control from the Components view and drop it in the main design area. You may want to expand the List control from its default size to accommodate the data in your database.
  3. Right-click the List control and select Bind To Data.
  4. In the Bind To Data dialog box, leave New Service Call selected, select CentreService as the Service, and select getCentreNames():String[] as the operation (see Figure 5).
  5. Click OK.
The Bind To Data dialog box
Figure 5. The Bind To Data dialog box

That’s it. Flash Builder 4 has generated all the code that’s needed to display the results of the service call in the List control.

  1. Run the application and you’ll see elements from the database in the list.Of course you’ll probably want to see more than just the Centre names.
  2. Drag a DataGrid control from the Components view and drop it in the main design area.
  3. This time drag the getCentres():Centre[] operation from the Data/Services view and drop it on the DataGrid control. (This is an alternative to selecting the control, right-clicking, and selecting Bind To Data.)
  4. Click OK in the Bind To Data dialog box.
  5. Run the program again and you’ll see that the entire table is shown.

The value object for the corresponding Centre class written in C# was automatically generated by Flash Builder 4. Here, the value object is essentially the same class written in ActionScript. To see the generated code, expand the valueObjects package in Package Explorer and open the Centre.as file. This ActionScript class can be reused for other purposes as a strongly typed class.

Where to go from here

Now that you have seen how easy it is to invoke a .NET-based web service from your Flex applications, you can use this approach to improve the richness of your web applications. With data-centric development you can even convert traditional web applications to Rich Internet Applications quickly and efficiently. For more information on data-centric development see the article Data-centric development with Flash Builder 4.

You could expand on this application in many ways. For example, you could use the data retrieved from the database to plot the location of offices (or even parcels) on a map. You can read more about how I developed a similar application using Google Maps on my blog.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Generating forms in Flash Builder 4
  • Tool-based approaches for data-centric RIA development
  • Flash Builder 4 and PHP – Part 3: Implicit paging and data management
  • Flash Builder 4 and PHP – Part 1: Data-centric development
  • Flash Builder 4 and PHP – Part 2: Zend AMF and Flash Remoting
  • Using the Flash Builder 4 data-centric features with Parsley (and other frameworks)
  • Building a Flex application that accesses an ASP.NET-based HTTP service with Flash Builder 4
  • Data paging with Flex and PHP using Flash Builder 4
  • Working with Doctrine 2, Zend AMF, Flex, and Flash Builder

製品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • モバイルアプリ
  • Photoshop
  • Touch Apps

ソリューション

  • デジタルマーケティング
  • コンテンツオーサリング
  • Web Experience Management

業種別ソリューション

  • 教育
  • 金融機関

サポート

  • ヘルプ&サポート
  • 注文と返品
  • ダウンロードに関するヘルプ
  • ユーザー登録に関するヘルプ

ラーニング

  • ADC: Adobe Developer Center
  • Adobe TV
  • Design Magazine
  • Photoshop Magazine
  • Focus In

ご購入方法

  • アドビストア
  • アカデミックストア
  • アドビライセンスストア
  • ボリュームライセンスについて
  • 販売パートナー
  • キャンペーン情報

ダウンロード

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

会社情報

  • プレスルーム
  • パートナープログラム
  • 企業の社会的責任(英語)
  • 採用情報
  • 投資家の皆様へ(英語)
  • イベント&セミナー
  • Legal(英語)
  • セキュリティ
  • お問い合わせ
国・地域および言語の選択 日本(変更)
国・地域および言語の選択 閉じる

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

利用条件 | プライバシーポリシーとCookie (更新)

Reviewed by TRUSTe: site privacy statement