c# - WCF,更改端点的 baseAdress

标签 c# .net wcf .net-3.5

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

<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. 如何添加另一个端点。我尝试使用端点 address="/Address2"binding="basicHttpBinding"contract="WcfReporting.IService1"/>

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

最佳答案

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

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

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

关于c# - WCF,更改端点的 baseAdress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/909332/

相关文章:

c# - IReflect 和 DispId

wcf - 在 Windows 窗体应用程序中托管 WCF 服务

在SoapUI上进行带有用户名身份验证的WCF Web服务

c# - ELMAH - 没有 HttpContext 的异常记录

c# - 为特定于域的操作创建独立的控制台(shell)

c# - 检测线程已在 C# .net 中运行?

c# - Moq:如何使用带有内部 HttpClient 的 Nunit 测试一个类?

.net - 在 .NET 中创建音乐播放器涉及什么?

c# - PowerCollections 中 GetValueElseAdd 的 BCL 等价物是什么

c# - 无需魔术弦即可分离屏幕