Provide OData Services of GMO MakeShop データ from a WCF Application

This article shows how to publish an OData feed of GMO MakeShop データ by creating a WCF Service Application.

加藤龍彦
ウェブデベロッパー


こんにちは!ウェブ担当の加藤です。マーケ関連のデータ分析や整備もやっています。

The CData ADO.NET Provider for GMOMakeShop enables you to use the Windows Communication Foundation (WCF) framework to rapidly develop service-oriented applications that provide GMO MakeShop データ to OData consumers. This article shows how to create an entity data model to provide the underlying connectivity to the GMO MakeShop データ, as well as how to create a WCF Data Service to expose the OData service. You can then consume the feed with any OData client, for example, Power Pivot or an application that uses the CData ADO.NET Provider for OData.

Create the OData Service

Follow the steps below to create a WCF service application that will provide connectivity to GMO MakeShop データ via OData.

  1. Open Visual Studio and create a new project. Select the WCF Service Application template.
  2. Delete the autogenerated IService.cs and Service1.svc.
  3. Click Project -> Add New Item -> ADO.NET Entity Data Model.
  4. In the Entity Data Model wizard that is displayed, select the 'EF Designer from Database' option.
  5. In the resulting Choose Your Connection dialog, click New Connection.
  6. In the Connection properties dialog, select the CData GMO MakeShop Data Source and enter the necessary credentials. A typical connection string is below:

    ShopId=MyShopId;ProductsAccessCode=MyProductsAccessCode;MembersAccessCode=MyMembersAccessCode;OrdersAccessCode=MyOrdersAccessCode;

    GMO MakeShop に接続するには、MembersAccessCode、OrdersAccessCode、ProductsAccessCode、およびShopId が必要です。

    GMO MakeShop へのアクセスの設定

    MembersAccessCode、OrdersAccessCode、ProductsAccessCode、およびShopId を取得するには、以下の手順に従ってください。

    • GMO MakeShop には各API のAccessCode が必要です。
    • GMO MakeShop Store Manager にログインし、メニューの「ショップ作成」をクリックします。
    • 左ナビゲーションメニューの「外部システム連携」から任意の連携対象設定ををクリックします(メニューに表示されない場合は別途GMO MakeShop にご確認ください)。
    • 商品データ連携設定の場合:認証コードの「発行」ボタンをクリックし、ProductsAccessCode を取得します。
    • 注文データ連携設定の場合:最初に「注文情報参照」と「注文情報変更」の設定を選択します。選択後、認証コードの「発行」ボタンをクリックし、OrdersAccessCode を取得します。
    • 会員データ連携設定の場合:最初に「会員情報の(参照・登録・変更・削除)」の設定を選択します。選択後、認証コードの「発行」ボタンをクリックし、MembersAccessCode を取得します。
    • 会員認証連携設定の場合:認証コードの「発行」ボタンをクリックし、ProductsAccessCode を取得します。

    GMO MakeShop アカウントの認証

    次の接続プロパティを設定して接続します。

    • ShopId:接続先のGMO MakeShop Store ID を設定。GMO MakeShop Store ID はログイン用の ID と同じです。
    • OrdersAccessCode:「注文データ連携設定」から取得した「認証コード」を設定。このプロパティは Orders テーブルにアクセスする場合に必要です。
    • ProductsAccessCode:「商品データ連携設定」から取得した「認証コード」を設定。このプロパティは Products テーブルにアクセスする場合に必要です。
    • MembersAccessCode:「会員データ連携設定」から取得した「認証コード」を設定。このプロパティは Members テーブルにアクセスする場合に必要です。
    • MemberAuthenticationCode:「会員認証連携設定」から取得した「認証コード」を設定。このプロパティは MemberAuthenticationConfirm を実行する場合に必要です。
    • Password:GMO MakeShop Store Manager のログインユーザーのパスワードを指定。このプロパティは ProductCategoryRegistrationOrModification,ProductMemberGroupPriceRegistrationOrModification,ProductOptionRegistrationOrModification,ProductRegistrationOrModification を実行する場合に必要です。

    See the help documentation for guides to connecting in Visual Studio.

    Required connection properties, specified in the Add Connection dialog. (Salesforce is shown.)
  7. Select GMO MakeShop tables and views that you want OData clients to access. Available tables in the Entity Data Model Wizard. (Salesforce is shown.)
  8. Click Project -> Add New Item -> WCF Data Service.
  9. Specify the data source class and configure access to the new WCF Data Service. In the example below, the Access Rule for the entities is set to All. This means that any user will be able to read and modify data.

    using System; using System.Collections.Generic; using System.Data.Services; using System.Data.Services.Common; using System.Linq; using System.ServiceModel.Web; using System.Web; namespace GMOMakeShopService{ public class GMOMakeShopDataService : DataService { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } } }
  10. Run the project. Applications that support OData can now access the Salesforce data and reflect any changes. You can access the feed in your browser. The feed will resemble the following:
  11. The raw OData feed. (Salesforce is shown.)

Consume the OData Service from Power Pivot

You can now use the service from any OData client; for example, Excel Power Pivot.

  1. Open Excel and click on the Power Pivot Window button.
  2. A new pop-up will appear. Select the option From Data Feeds.
  3. In the resulting Table Import Wizard, enter the OData URL. For example, http://localhost:12449/GMOMakeShopDataService.svc/. The OData URL for GMO MakeShop.
  4. After connecting to the OData service, click the Next button at the bottom of the window.
  5. A table listing of the available tables will appear in the next window of the wizard. Select which tables you want to import and click Finish. Available tables in the Table Import Wizard. (Salesforce is shown.)
  6. Click Close to import the data in Power Pivot. The table loaded in Power Pivot. (Salesforce is shown.)

関連コンテンツ

トライアル・お問い合わせ

30日間無償トライアルで、CData のリアルタイムデータ連携をフルにお試しいただけます。記事や製品についてのご質問があればお気軽にお問い合わせください。