2008-12-02 70 views

回答

5

確定您可以根據需要(甚至是不同的WCF服務)在Web應用程序內公開儘可能多的端點。這不應限於IIS或WPAS。

這樣做將使您能夠訪問任何種類的共享數據。儘管我通常會建議不要使用靜態變量來共享信息(但我當然不知道你的要求)。

2

當然。在Visual Studio中,只需添加另一個WCF服務項目。 IIS將在同一個AppDomain中運行這兩個服務。在這個例子中,我首先創建一個圖書館,只有下面的接口定義:

namespace ServiceInterface 
{ 
    [ServiceContract] 
    public interface IClass 
    { 
     [OperationContract] 
     string GetMessage(); 
    } 
} 

然後我創建了一個VS Web應用程序,並添加兩個服務:MyServiceService2這都實現IClass。這是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> 

在客戶端應用程序我的web.config文件部分,你的配置信息可能看起來像:

<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> 
0

是的,你可以在IIS和WPAS都做到這一點。但這樣做的唯一方法是在同一個程序集AFAIK中編譯這兩個服務。