IIS7 または WPAS で WCF サービスをホストする場合、2 つ以上のサービスを同じ AppDomain にロードして、静的変数を共有できるようにすることはできますか?
1585 次
3 に答える
5
確かに、 Web アプリケーション内で必要な数のエンドポイントを公開できます (異なる WCF サービスであっても)。これは、IIS または WPAS に限定されるべきではありません。
そうすることで、あらゆる種類の共有データにアクセスできるようになります。通常、静的変数を使用して情報を共有することはお勧めしませんが(もちろん、あなたの要件はわかりません)。
于 2010-04-24T19:46:56.720 に答える
2
もちろん。Visual Studio では、別の WCF サービス アイテムを追加するだけです。IIS は、同じ AppDomain で両方のサービスを実行します。この例では、最初に次のインターフェイス定義のみを含むライブラリを作成しました。
namespace ServiceInterface
{
[ServiceContract]
public interface IClass
{
[OperationContract]
string GetMessage();
}
}
次に、VS で Web アプリケーションを作成し、次の 2 つのサービスを追加しMyService
ましService2
たIClass
。これは私のweb.configファイルセクションですserviceModel
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WebService1.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="WebService1.Service2Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WebService1.MyServiceBehavior"
name="WebService1.MyService">
<endpoint address="" binding="wsHttpBinding" contract="ServiceInterface.IClass">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="WebService1.Service2Behavior"
name="WebService1.Service2">
<endpoint address="" binding="wsHttpBinding" contract="ServiceInterface.IClass">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
クライアント アプリケーションでは、構成情報は次のようになります。
<client>
<endpoint address="http://mymachinename.local/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClass"
contract="ServiceReference1.IClass" name="WSHttpBinding_IClass">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://mymachinename.local/Service2.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClass1"
contract="ServiceReference2.IClass" name="WSHttpBinding_IClass1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
于 2010-04-24T20:56:10.353 に答える
0
はい、IIS と WPAS の両方で実行できます。しかし、それを行う唯一の方法は、両方のサービスを同じアセンブリでコンパイルすることです。
于 2010-04-25T01:52:10.123 に答える