同时托管多个WCF服务 - 它们共享服务名称

时间:2013-08-29 01:45:29

标签: c# wcf localhost

我有一个WCF服务库项目,其中我有2个具有[ServiceContract]属性的类。

我有一个控制台应用程序,它将托管这两项服务。

代码:

Uri baseAddressRetrieve = new Uri("http://localhost:8000/api/Retrieve/");
Uri baseAddressStorage = new Uri("http://localhost:8005/api/Storage/");

ServiceHost hostRetrieve = new ServiceHost(typeof(Retrieve), baseAddressRetrieve);
ServiceHost hostStorage = new ServiceHost(typeof(Storage), baseAddressStorage);

hostRetrieve.AddServiceEndpoint(typeof(IRetrieve), new WSHttpBinding(SecurityMode.None), "Retrieve");
hostStorage.AddServiceEndpoint(typeof(IStorage), new WSHttpBinding(SecurityMode.None), "Storage");

hostRetrieve.Open();
hostStorage.Open();

现在,当我通过URI访问这两个服务地址时,它们都标记为“存储服务”,并且在生成的代码中都有这行代码:

StorageClient client = new StorageClient();

当然,Retrieve服务应该是RetrieveClient吗?

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="NS.Retrieve">
        <endpoint address="" binding="basicHttpBinding" contract="NS.IRetrieve">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/NS/Retrieve/"/>
          </baseAddresses>
        </host>
      </service>
      <service name="NS.Storage">
        <endpoint address="" binding="basicHttpBinding" contract="NS.IStorage">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/NS/Storage/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

0 个答案:

没有答案
相关问题