【问题标题】:How-to: Moving WCF service from localhost to production server操作方法:将 WCF 服务从 localhost 移动到生产服务器
【发布时间】:2011-01-08 22:41:04
【问题描述】:

我在我的开发机器上构建了一个 WCF Web 服务。我构建了服务,创建了一个测试客户端,测试了一切,它工作正常。我开始对这个 WCF 的东西感觉很好。然后我很勇敢,把它移到了我的生产服务器上。

目前,生产服务器位于 WinHost.com。我有我的测试域 www.MyDomain.com,创建了一个应用程序文件夹 /websvc,并将 Web 服务文件复制到其中。服务地址为http://www.MyDomain.com/websvc/eval.svc

现在我已移至生产服务器,我无法使用 Web 服务。我收到此错误 - “此集合已包含带有方案 http 的地址。”我用谷歌搜索了解决方案的消息,尝试了一些,但这只会导致其他错误。所以我重置了所有内容,然后重新开始。

根据上面的服务地址,我的 web.config 应该是什么样子的?具体来说,我的端点应该如何看待它?

这是我现在所拥有的......

<configuration>
  <system.serviceModel>
    <services>
      <service name="EvalServiceLibrary.EvalService">
        <endpoint address="http://www.MyDomain.com:80/websvc/mex"
          binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="http://www.MyDomain.com:80/websvc/basic"
          binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- 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>
</configuration>

【问题讨论】:

  • 这是您在尝试使用应用程序中的服务时收到的消息吗?启用includeExceptionDetailInFaults,然后在您的浏览器中导航到该服务的位置。它会显示什么?顺便说一句,您在问题中列出的地址与 Web.config 文件中的端点地址不匹配。
  • 能否指出端点地址的区别?我没有看到它。当我尝试访问 MyDomain.com:80/websvc/eval.svc/basic 时,错误消息显示在我的浏览器中
  • 描述中的地址是websvc/eval.svc,而配置中的地址是basic

标签: visual-studio-2008 wcf .net-3.5


【解决方案1】:

每次我遇到这种情况,都是因为 IIS 按名称为多个虚拟主机配置(托管场景中的常见配置)。 Here 是一种修复它的好方法,它一直对我有用 - 请注意,您需要明确且准确地定义您的端点地址,包括正确的主机名(看起来您或多或少有)。

我已经提交了有关此问题的连接错误,据说它对 4.0 更好,但我还没有尝试过。

【讨论】:

    【解决方案2】:

    Web 服务现在可以在如上所述的第三方服务上运行和托管。正在使用的 web.config 如下所示。

    经验教训:为 WCF Web 服务编写代码并不难,但配置端点可能有点挑战。

    <?xml version="1.0"?>
    <!--
        Note: As an alternative to hand editing this file you can use the 
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in 
        machine.config.comments usually located in 
        \Windows\Microsoft.Net\Framework\v2.x\Config 
    -->
    <configuration>
    
      <system.serviceModel>
    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false">
          <!-- modified section here-->
          <baseAddressPrefixFilters>
            <add prefix="http://www.MyDomain.com:80/websvc/eval.svc"/>
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
    
        <services>
          <service behaviorConfiguration="ServiceBehavior" name="EvalServiceLibrary.EvalService">
            <endpoint address="" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
    
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <!-- 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>
    
    </configuration>
    

    【讨论】:

      【解决方案3】:

      这只是意味着当您在 IIS 中托管服务时,无需指定基地址。它已经由 IIS 虚拟目录定义。只需将您的块替换为:

      <services>
        <service name="EvalServiceLibrary.EvalService">
          <endpoint address="mex"
            binding="mexHttpBinding" contract="IMetadataExchange" />
          <endpoint address="basic"
            binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
        </service>
      </services>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-03
        • 1970-01-01
        相关资源
        最近更新 更多