Windows Azure Tips from Prospex

システム開発 × インフラ構築・運用 × グラフィックデザイン = プロスペックス

Windows Azure Service Bus の検証

clock November 3, 2011 14:54 by author Nakajima

 

Windows Azure Service Busについて、現在、検証を行っていますが、分かっていることを記載します。

下記のサイトでオンプレミス環境とWindows Azure Service Bus の連携について紹介されていたので

実際に試してみました。

http://www.atmarkit.co.jp/fdotnet/bookpreview/progwinazure_0601/progwinazure_0601_02.html

すごくわかりやすく記載されています。

 

1. 準備

(1) Windows Azure Service Busの名前空間を設定する

image

(2) プロパティの既定のキーをメモしておく

 

2. ローカルPCでオンプレミス側のサービスをデバック実行し公開する (ソースコードなどは先ほど紹介したサイトをご参照ください)

image

そうするとサービスバスの登録情報に表示されていることがわかります。

image

 

今日の本題はこれからです。

 

3. Windowsサーバー(オンプレミス環境) でサービスを公開する。

 

以下のような環境で行いました。

・Windows Server 2003 (IIS6.0)

・SQL Server 2005

 

Windowsサーバー(オンプレミス環境) でサービスを公開すると以下のようなエラーが発生しました。

image

もちろん、以下のサービスバスの登録情報のサイトでもサービスは確認はできません。

image

 

そこで、こちらのエラーについて、ネットで情報を探していると以下の情報投稿サイトにたどり着きました。

http://social.msdn.microsoft.com/Forums/ja-JP/windowsazureja/thread/0434b839-b847-4edb-9a7a-57857976f5f9/

 

どうも、オンプレミス側に「AppFabric SDK」が必要と記載してあります。

 

そこで、Windows サーバーに「AppFabric SDKをインストールしてみました。

そしてサービスを公開すると・・・ (以下のページはオンプレミス側で実際にサイトが公開されているか確かめるためにつくったテストのページです)

先ほどのエラーが発生しないようです。

image

そして、サービスバスの登録情報を確認するとサービスが確認できました。

image

 

結果から、Windows サーバー(オンプレミス環境)に「AppFabric SDK」をインストールするとサービスバスと連携できることが

確認できましたが、インストールなしでできないのか、まだまだ検証が必要なところです。

 

 

 

 

 

 

 



とても、良い本です。(「2」って……)

clock May 25, 2011 23:06 by author fujii

今回も、「Windows Azure platform AppFabric」をやってみます。

前回はサービスを作ったので、今回はクライアントを作ります。

今回の内容も、ほぼ下記の本そのままです。

とても、良い本です。(いつもお世話になっております)

Windows Azureアプリケーション開発入門

前回は、Namespaceを「helloappfabric」で作ったのですが、当分使わないと思い、削除してしました。

今回、「helloappfabric」で作ろうとしたら、名前が重複して作れなかったので、

泣く泣く「helloappfabric2」にしました。

image

なので、「app.config」の「solutionnamespace」を「helloappfabric2」に変更しました。

   1: <?xml version="1.0" encoding="utf-8" ?>
   2:  
   3: <configuration>
   4:  
   5:   <appSettings>
   6:     <add key="solutionnamespace" value="helloappfabric2"/>
   7:     <add key="issuer" value="owner"/>
   8:     <add key="accountkey" value="????????????????????????????????????????????"/>
   9:   </appSettings>
  10:   
  11:   <system.serviceModel>
  12:     <services>
  13:       <service name="HelloAppFabricService.HelloAppFabric">
  14:           <endpoint binding="netTcpRelayBinding" contract="HelloAppFabricService.IHelloAppFabric"/>
  15:       </service>
  16:     </services>
  17:   </system.serviceModel>
  18:  
  19: </configuration>

デバッグ実行して……

image 

「Service Gatewey」を表示すると、居ました。

image

けど、「Namespace」を「helloappfabric2」に変更してしまったので、

「sb://helloappfabric2.servicebus.windows.net/helloappfabric/」になってしまいました。

「2」って……テンション下がるなぁ。

気を取り直して、クライアントを作ってみました。

「Web Role」を「良い本」と同じ名前で追加しました。

image

ソリューションの構成は、下の図です。

image

参照設定ですが、サービスと同じです。

「IHelloAppFabric.vb」もサービスと同じなので、サービスのものを「リンクとして追加」しています。

「web.config」は、下記のようにしました。

   1: <appSettings>
   2:   <add key="solutionnamespace" value="helloappfabric2" />
   3:   <add key="issuer" value="owner" />
   4:   <add key="accountkey" value="????????????????????????????????????????????" />
   5: </appSettings>
   6:  
   7: <system.serviceModel>
   8:   <client>        
   9:     <endpoint name="RelayEndpoint" binding="netTcpBinding" contract="HelloAppFabric_WebRole.IHelloAppFabric" />
  10:   </client>
  11: </system.serviceModel>

「IHelloAppFabric.vb」を作ったとき、名前空間を指定しなかったので、

「endpoint」要素の「contract」を「HelloAppFabric_WebRole.IHelloAppFabric」にしました。

見つからないって、さんざん怒られたので……

image

「IHelloAppFabric.vb」を作ったとき、ちゃんと名前空間を指定して、

サービスとクライアントの「endpoint」要素の「contract」は同じにしておいた方が良いと思います。

あと、「binding="netTcpBinding"」としておくのが、ポイントです。

理由は、「良い本」に書いてあります。

「WebForm1.aspx」の「body」は、こんな感じ。

   1: <body>
   2:     <form id="form1" runat="server">
   3:     <div>
   4:         <asp:Button ID="btnSayHello" runat="server" Text="好きです" />
   5:         
   6:         <asp:TextBox ID="txtYourName" runat="server" />    
   7:     </div>
   8:     <div>
   9:         <asp:Label ID="lblMessageText" runat="server" />
  10:     </div>
  11:     </form>
  12: </body>

「WebForm1.aspx.vb」はこんな感じ。

   1: Imports System.Configuration
   2: Imports System.ServiceModel
   3: Imports System.ServiceModel.Description
   4: Imports Microsoft.ServiceBus
   5: Imports Microsoft.ServiceBus.Description
   6:  
   7: Public Class WebForm1
   8:     Inherits System.Web.UI.Page
   9:  
  10:     Private Sub btnSayHello_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSayHello.Click
  11:  
  12:         ' エンドポイントのURIを生成
  13:         Dim serviceUri As Uri = ServiceBusEnvironment.CreateServiceUri("sb", ConfigurationManager.AppSettings("solutionnamespace"), "helloappfabric")
  14:  
  15:         ' エンドポイントに対する資格情報を生成し設定
  16:         Dim SBCredential As New TransportClientEndpointBehavior
  17:         SBCredential.CredentialType = TransportClientCredentialType.SharedSecret
  18:         SBCredential.Credentials.SharedSecret.IssuerName = ConfigurationManager.AppSettings("issuer")
  19:         SBCredential.Credentials.SharedSecret.IssuerSecret = ConfigurationManager.AppSettings("accountkey")
  20:  
  21:         ' クライアントチャンネルファクトリを生成し設定
  22:         Dim channelFactory As New ChannelFactory(Of IHelloAppFabricAppChannel)("RelayEndpoint", New EndpointAddress(serviceUri))
  23:         channelFactory.Endpoint.Binding = New NetTcpRelayBinding
  24:         channelFactory.Endpoint.Behaviors.Add(SBCredential)
  25:  
  26:         ' クライアントチャンネルを生成しOpen
  27:         Dim channel As IHelloAppFabricAppChannel = channelFactory.CreateChannel
  28:         channel.Open()
  29:  
  30:         ' サービスメソッドの使用
  31:         lblMessageText.Text = channel.SayHello(txtYourName.Text)
  32:  
  33:         ' 閉じる
  34:         channel.Close()
  35:         channelFactory.Close()
  36:  
  37:     End Sub
  38:  
  39: End Class

「好きです」ボタンを押すと、処理を実行します。

「エンドポイントに対する資格情報」までは、サービスと同じです。

「channelFactory.Endpoint.Binding = New NetTcpRelayBinding」がポイントですが、

こちらの理由も「良い本」に書いてあります。

あと、「Microsoft.ServiceBus」の参照プロパティの「ローカル コピー」を「True」にします。

image

こちらの理由も「良い本」に書いてあります。

で、デプロイする時間はあるのか……終電との戦いだ。

…………できた!

名前を入力し……「好きです」ボタンをクリック!

image

「私も好きです。」って言われちゃったよ、えへへ。

サービス過剰じゃねーのか?

image

で、過剰なサービスはこちら。

image

何だ、この悲しいブログは!

今度は、もっとかっこいいサービスを作ろう……

 



とても、良い本です。

clock April 25, 2011 21:07 by author fujii

今日は、「Windows Azure platform AppFabric」をやってみます。

今日の内容ほ、ほぼ下記の本そのままです。

とても、良い本です。

Windows Azureアプリケーション開発入門

本は「C#」だけど、丸写しになるので「VB.NET」でやってみます。

準備については、既にブログで書かれています。

Windows Azure AppFabric SDK V1.0

image

32bitなので、下記をダウンロードして……

image

インストールしました。

image

image

image

今日は、サービスを作ってみます。

AppFabric のWCFサービスとして、コンソールアプリケーションを作成します。

もちろん、コンソールアプリである必要はありません。

image

WCFサービスを追加します。

image

「IHelloAppFabric.vb」にWCFコントラクトの定義を書きます。

「SayHello」というメッソッドを定義しました。

<OperationContract()>  属性が必要です。

ポイントは「IHelloAppFabricAppChannel」で、クライアント作成時に必要となるそうです。

   1: Imports System.ServiceModel
   2:  
   3: ' メモ: コンテキスト メニューの [名前の変更] コマンドを使用すると、コードと config ファイルの両方で同時にインターフェイス名 "IHelloAppFabric" を変更できます。
   4: <ServiceContract()>
   5: Public Interface IHelloAppFabric
   6:  
   7:     <OperationContract()>
   8:     Sub DoWork()
   9:  
  10:     <OperationContract()>
  11:     Function SayHello(ByVal yourname As String) As String
  12:  
  13: End Interface
  14:  
  15: Public Interface IHelloAppFabricAppChannel
  16:     Inherits IHelloAppFabric
  17:     Inherits IClientChannel
  18:  
  19: End Interface

「HelloAppFabric.vb」に動きを書きます。

「SayHello」なのに、名前を入力すると、「好きです。」と言ってくれる予定です。

   1: ' メモ: コンテキスト メニューの [名前の変更] コマンドを使用すると、コードと config ファイルの両方で同時にクラス名 "HelloAppFabric" を変更できます。
   2: Public Class HelloAppFabric
   3:     Implements IHelloAppFabric
   4:  
   5:     Public Sub DoWork() Implements IHelloAppFabric.DoWork
   6:     End Sub
   7:  
   8:     Public Function SayHello(ByVal yourname As String) As String Implements IHelloAppFabric.SayHello
   9:  
  10:         Console.WriteLine(yourname & "さんからリクエストがありました。")
  11:         Return yourname & "さん、好きです。"
  12:     End Function
  13:  
  14: End Class

ここまでは、普通の「WCFサービス」です。

AppFabricを通じて、「WCFサービス」を公開する為の情報を「app.config」に書きます。

当然、先に Namespace を作成します。

image

「helloappfabric」にしました。

 image

「appSettings」に情報を書きます。

「Namespace」の「Name」と「Service Bus」の「Default Key」をそのまま「value」に書きます。

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3:   <appSettings>
   4:     <add key="solutionnamespace" value="helloappfabric"/>
   5:     <add key="issuer" value="owner"/>
   6:     <add key="accountkey" value="???????????????????????????????????????????????"/>
   7:   </appSettings>
   8:     <system.serviceModel>
   9:         <services>
  10:             <service name="HelloAppFabricService.HelloAppFabric">
  11:                 <endpoint address="" binding="netTcpRelayBinding" contract="HelloAppFabricService.IHelloAppFabric"></endpoint>
  12:             </service>
  13:         </services>
  14:     </system.serviceModel>
  15: </configuration>

「Main」に公開のためのコードを書きます。

   1: Imports System.Configuration
   2: Imports System.ServiceModel
   3: Imports System.ServiceModel.Description
   4: Imports Microsoft.ServiceBus
   5: Imports Microsoft.ServiceBus.Description
   6:  
   7:  
   8: Module Module1
   9:  
  10:     Sub Main(ByVal args As String())
  11:  
  12:         ' エンドポイントのURIを生成するメソッド
  13:         Dim adress As Uri = ServiceBusEnvironment.CreateServiceUri("sb", ConfigurationManager.AppSettings("solutionnamespace"), "HelloAppFabric")
  14:  
  15:         'エンドポイントに対する資格情報を生成
  16:         Dim SBCredential As New TransportClientEndpointBehavior
  17:         SBCredential.CredentialType = TransportClientCredentialType.SharedSecret
  18:         SBCredential.Credentials.SharedSecret.IssuerName = ConfigurationManager.AppSettings("issuer")
  19:         SBCredential.Credentials.SharedSecret.IssuerSecret = ConfigurationManager.AppSettings("accountkey")
  20:  
  21:         ' ServiceHostのインスタンスを生成
  22:         Dim host As ServiceHost = New ServiceHost(GetType(HelloAppFabric), adress)
  23:  
  24:         ' エンドポイントにServiceRegistryの設定を反映
  25:         Dim serviceRegistryStteing As IEndpointBehavior = New ServiceRegistrySettings(DiscoveryType.Public)
  26:  
  27:         ' エンドポイント構成にServiceBusの資格情報を追加
  28:         For Each endpoint As ServiceEndpoint In host.Description.Endpoints
  29:             endpoint.Behaviors.Add(serviceRegistryStteing)
  30:             endpoint.Behaviors.Add(SBCredential)
  31:         Next
  32:  
  33:         ' サービスをオープン
  34:         host.Open()
  35:         Console.WriteLine("Service Started...")
  36:         Console.WriteLine("Press [Enter] to exit")
  37:         Console.ReadLine()
  38:         host.Close()
  39:  
  40:     End Sub
  41:  
  42: End Module

「Microsoft.ServiceBus」への参照が必要なので、「Microsoft.ServiceBus.dll」を参照として追加します。

「Windows Azure AppFabric SDK」をインストールしたフォルダの、「Assemblies」以下にあります。

image

そのほかの参照も追加しておきます。

image 

image

エラーが出たので……

image

対象のフレームワークを……

image

変更してみました。

image

デバッグで実行して……

image

ブラウザに「Service Gateway」を表示すると……居ました。

ちゃんと公開されているようです。

image

次回は、クライアントを作ってみます。



Windows Azure SDK 1.3 Full IISの罠

clock February 2, 2011 16:05 by author Sekine

Azure SDK 1.3 には新しい機能が追加されましたが、

その中に、Full IIS というのがあります。

仮想OS上のIISとして、ホストするという事なのですが、

当たり前と言えば当たり前。



ここに、大きな落とし穴があります。

実行時の RoleEntryPoint は別アプリケーションドメインで実行されるという事。

 

Visual Studio でWebアプリケーションを作成すると、

WebRole.cs (.vb) 内で、

RoleEntryPoint 継承クラス、OnStartメソッド内で、

CloudStorageAccount.SetConfigurationSettingPublisher の設定やら、

ログ転送のための、DiagnosticMonitorの設定など行っていました。

アプリケーションの初期処理なども、ここに記述していたかと思います。

それが普通だったのですが、SDK 1.3 & Full IIS では、

Webアプリケーションとは別のアプリケーションドメインで、RoleEntryPoint が実行されるので、

RoleEntryPoint . OnStart で設定しても、Webアプリケーションの動作には反映されなくなります。

 

解決方法は、

アプリケーション側、パイプライン処理の Global.asax で Application_Start に、全処理を移す事です。

SDK 1.2 で動作していたのを、1.3 で書きなおしたときに動作がおかしいと思ったら見直してみましょ。

 

以下せつめい

Full IIS と、Hosted Web Core について、

SDK 1.2 までは、Hosted Web Core (WaWebHost.exe)が Web Role をホストして、Webアプリケーションを動作させていました。


SDK 1.3 の登場と Full IIS 設定では、IIS (w3wp.exe)が Web Role をホストします。

但し、Web Role を動作させる際に読まれる RoleEntryPoint を処理するのは、WaIISHost.exe という別のプロセスが処理を行います。

わかりましたね!!(?)

 

簡単言えば、別々のプロセスなので、RoleEntryPoint で初期設定をしても無駄ってことです。

 

Visual Studio + SDK 1.3 では、Azure アプリケーション Web ロールを作成すると、

ServiceDefinition.csdef は、デフォルトで Full IIS の設定になります。

こんな感じ、
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzureSample"
                   xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebRole1">

    <!-- ここから Full IIS 設定 -->
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1"
                   endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <!-- ここまで -->

    <Endpoints>
      <InputEndpoint name="Endpoint1"
                     protocol="http"
                     port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
    <ConfigurationSettings>
      <Setting name="DataConnectionString" />
    </ConfigurationSettings>
  </WebRole>
</ServiceDefinition>

Hosted Web Core で動作させたい場合は、Sites要素をバッサリ削除します。

 

さて、

Global.asax に処理は移し、

Application_Start を確認したく、ブレークポイントを張った。

デバッガが止まってくれない....

どうやらこれは、デバッガがアタッチするタイミングに問題があるという事なので、

protected void Application_Start()
{
System.Diagnostics.Debugger.Break();
..


と、することで、ちゃんとブレークに引っかかります。

 

関根:



Sign In