代码之家  ›  专栏  ›  技术社区  ›  Scott Mitchell

WCF配置在本地主机上工作,而不是在共享网站上

  •  0
  • Scott Mitchell  · 技术社区  · 6 年前

    共享托管网站 ,我得到一个例外:

    我不能改变,因为这是一个共享的环境。

    Web.config 关于服务?我得到的是:

    <system.serviceModel>
      <services>
        <service name="BoggleService">
          <endpoint binding="webHttpBinding" contract="Solver" behaviorConfiguration="webHttp"/>
        </service>
      </services>
      <behaviors>
        <endpointBehaviors>
          <behavior name="webHttp">
            <webHttp/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
    </system.serviceModel>
    

    我也有这个配置,但是它被注释掉了(就像我说的,一个很久以前的项目,试图恢复它):

    <serviceHostingEnvironment>
      <baseAddressPrefixFilters>
        <add prefix="http://www.example.com/"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    

    二者都

    索引超出范围。必须为非负且小于集合的大小。

    下面是完整的堆栈跟踪:

    [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index]
       System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +64
       System.ThrowHelper.ThrowArgumentOutOfRangeException() +15
       System.Collections.Generic.List`1.get_Item(Int32 index) +7515544
       System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage) +82
       System.ServiceModel.Web.WebServiceHost.OnOpening() +203
       System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +229
       System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +121
       System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
    
    [ServiceActivationException: The service '/Solver.svc' cannot be activated due to an exception during compilation.  The exception message is: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index.]
       System.ServiceModel.AsyncResult.End(IAsyncResult result) +11667006
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
       System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +275
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    

    这是来自WCF的内部——它不是来自我的代码(堆栈跟踪显示它永远不会到达我的代码,如果我运行调试器并在代码中设置断点,它永远不会到达)。

    <baseAddressPrefixFilters> 设置为 http://localhost

    谢谢!

    0 回复  |  直到 6 年前
        1
  •  0
  •   Abraham Qian    6 年前

    我认为这个问题可以简化,因为它使用WebHttpBinding来托管Restful风格的服务。
    在。网4.5,我们可以使用以下简化配置来托管Restful样式的服务。

      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior>
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="webHttpBinding" scheme="http" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    

    默认情况下,webhttpbinding使用WebHttpSecurityMode.None。因此,上面的身份验证架构错误不太可能发生。如果需要,不要忘记在IIS身份验证模块中启用身份验证模式。
    尝试用我的配置替换您的配置,并在IIS站点绑定模块中提供http绑定。

    推荐文章