【问题标题】:WCF, changing the baseAdress of an endpointWCF,更改端点的baseAdress
【发布时间】:2010-10-28 21:40:01
【问题描述】:

我对以下配置文件有几个问题:

<system.serviceModel>
  <bindings />
  <services>
    <service behaviorConfiguration="WcfReporting.Service1Behavior"
             name="WcfReporting.Service1">
      <endpoint address="" 
                binding="basicHttpBinding" bindingConfiguration=""
                contract="WcfReporting.IService1">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" 
                contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:5050/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="WcfReporting.Service1Behavior" >
        <!-- To avoid disclosing metadata information, set the value below to false 
             and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true"/>
        <!-- To receive exception details in faults for debugging purposes, 
             set the value below to true. Set to false before deployment to 
             avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
  1. 为什么当我按 F5 重新启动服务时,服务以这个 URL http://localhost:2752/ 开始...为什么不是我在 baseAddresses 中指定的 5050。

  2. 如何添加另一个端点。我尝试使用端点地址="/Address2" binding="basicHttpBinding" contract="WcfReporting.IService1" />

我应该如何访问该服务,不仅可以使用http://localhost/VirtualDir/,还可以使用http://localhost/VirtualDir/address2,或者它是如何工作的?

【问题讨论】:

    标签: c# .net wcf .net-3.5


    【解决方案1】:

    如果您在 Visual Studio 2005 或更高版本中托管 Cassini,则可以使用 Project/Properties/Web/Use Visual Studio Development Server/Specific Port 指定端口。

    默认情况下,端口将自动分配 - 这对 Web 服务不是很有帮助,因为您的客户可能希望使用固定 URL。

    在 IIS 或 Cassini 中托管时,您无需在配置文件中指定 - 基本 URL 由 Web 服务器提供。 元素在自托管时使用。

    【讨论】:

      【解决方案2】:

      如何添加另一个端点。一世 尝试使用端点 地址="/地址2" 绑定="基本HttpBinding" contract="WcfReporting.IService1" />

      您在此端点中指定的地址需要是本地的和相对的 - 例如只需指定

      <endpoint address="Address2"
                binding="basicHttpBinding"
                contract="WcfReporting.IService1" />
      

      这将在

      的完整地址处创建一个端点
      net.tcp://localhost:5050/Address2
      

      但正如 Darin 已经指出的那样 - 如果您使用 IIS / WAS 来托管您的服务,您的 *.svc 文件所在的虚拟目录将优先,并且指定的基地址将被忽略。为了真正使用基地址,您需要在控制台应用程序或 Windows 服务中自行托管服务。

      马克

      【讨论】:

        【解决方案3】:

        如果您使用 Web 服务器(例如 Cassini 或 IIS)来托管您的 WCF 服务,则将从该服务器提供基地址。另请注意,您不能通过 HTTP 使用 TCP 绑定。如果您希望能够设置您需要自己托管服务的基地址属性(例如在 NT 服务、控制台或 Windows 应用程序中)。

        【讨论】:

        • 谢谢。因此,如果我添加一个像这样的端点 当我点击 F5 是我的服务然后通过 TCP 托管还是我实际上必须在控制台应用程序中编写代码才能做到这一点?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 2011-10-19
        相关资源
        最近更新 更多