方法:将WCF服务从localhost移动到生产服务器

时间:2010-01-25 02:05:27

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

我在开发机器上构建了一个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>

3 个答案:

答案 0 :(得分:1)

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

我已经在此处提交了连接错误,而且据说4.0更好,但我还没有尝试过。

答案 1 :(得分:1)

如上所述,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>

答案 2 :(得分:0)

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

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