为什么我们不能用ServiceHost注册多个基地址(共享相同的传输协议)?

时间:2010-11-17 19:17:10

标签: wcf

  

我们可以注册多个基地   使用Servicehost的地址,只要   地址不使用相同的传输   协议:

     

ServiceHost host = new   的ServiceHost(typeof运算(为MyService)   tcpBaseAddress,httpBaseAddress);

不允许ServiceHost注册使用相同传输协议的多个基地址的原因是什么?

1 个答案:

答案 0 :(得分:1)

我想因为WCF配置机制不知道用哪个基地址来解析相对地址。

来自http://msdn.microsoft.com/en-us/library/ms734786.aspx

<service name="Microsoft.ServiceModel.Samples.CalculatorService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
<!-- Not allowed, just for demonstration purposes -->
            <add baseAddress="http://localhost:8000/ServiceModelSamples/serviceOther"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="/test"
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="http://localhost:8001/hello/servicemodelsamples"
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="net.tcp://localhost:9000/servicemodelsamples/service"
                  binding="netTcpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <!-- the mex endpoint is another relative address exposed at 
             http://localhost:8000/ServiceModelSamples/service/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

在上面的例子中,对于所有第一个,第二个和mex-Endpoint,都无法确定要使用哪个“baseAddress”。