- - PR -
Webアプリケーション間で利用可能なSingletonリモートオブジェクト
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2003-11-04 21:59
はじめまして。
Kato103と申します。 ASP.NETアプリケーション間で同一のオブジェクトを参照したいと思っています。 実現手段としてSingletonのリモートオブジェクトを利用したところ、 ASP.NETアプリケーション毎にインスタンスが作成されてしまっています。 下記にソースコードを記載しました。 クライアント1・2は別のASP.NETアプリケーションです。 どうにかクライアント1・2から同一のリモートオブジェクトにアクセスしたく思っています。 お知恵を貸していただけませんでしょうか。 よろしくお願いします。 リモートオブジェクト(アプリケーション名:RemoteComponent) ServiceClass.vb −−−−−−−−−−−−−−−−−−−−−−−− Public Class ServiceClass Inherits MarshalByRefObject Private Shared _singleton As New ServiceClass() Private Shared count1 As Integer = 0 Private Sub New() End Sub Public Shared Function GetCount() As Integer count1 += 1 Return count1 End Function End Class リモートオブジェクトアプリケーション名:RemoteComponent) Web.config −−−−−−−−−−−−−−−−− <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> <service> <wellknown mode="Singfleton" objectUri="SAService.rem" type="ServiceClass, ServiceClass"/> </service> <channels> <channel ref="http"/> </channels> </application> </system.runtime.remoting> </configuration> クライアント1(アプリケーション名:RemoteClient1) WebForm1.aspx.vb −−−−−−−−−−−−−−−−−−− Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' リモートオブジェクトの変数値を取得 Label1.Text = RemotingComponent.ServiceClass.GetCount End Sub クライアント1(アプリケーション名:RemoteClient1) global.asax.vb −−−−−−−−−−−−−−−−−−− Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' アプリケーションが開始されたときに発生します。 ' リモートオブジェクトを初期化 RemotingConfiguration.Configure("c:\inetpub\wwwroot\RemotingClient\Client.config") End Sub クライアント1(アプリケーション名:RemoteClient1) Client.config −−−−−−−−−−−−−−−−−−− <configuration> <system.runtime.remoting> <application> <channels> <channel ref="http" useDefaultCredentials="true" port="0"> <clientProviders> <formatter ref="binary"/> </clientProviders> </channel> </channels> <client> <wellknown url="http://localhost:80/RemotingComponent/SAService.rem" type="ServiceClass, ServiceClass"/> </client> </application> </system.runtime.remoting> </configuration> クライアント2(アプリケーション名:RemoteClient2) WebForm1.aspx.vb −−−−−−−−−−−−−−−−−−− Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' リモートオブジェクトの変数値を取得 Label1.Text = RemotingComponent.ServiceClass.GetCount End Sub 上記クライアント2のコードはクライアント1のコードと同一です。 |
|
投稿日時: 2003-11-05 10:02
リモート呼び出しが行われていないと思います。
[ServiceClass.vb] Public Shared Function GetCount() As Integer を以下のように変更して再度実行してください。 Public Function GetCount() As Integer #クライアントアプリケーションの呼び出し部分も #変更してください。 |
1