【问题标题】:The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http baseaddServiceMetadataBehavior的HttpGetEnabled属性设置为true,HttpGetUrl属性是相对地址,但是没有http baseadd
【发布时间】:2014-06-20 10:35:16
【问题描述】:

我有一个启用 ADFS 的 asp.net mvc2 应用程序,并在 IIS 中配置了 HTTPS 绑定(端口号:443)。该站点在 IIS 中配置为 DefaultWebSite。我有一个 WCF 服务:asp.net mvc2 项目中的 ChartsService.svc,该项目用于同一解决方案中存在的 silverlight 项目。在本地开发环境完成测试后,我已经将代码部署到更高的环境。它在所有环境中都没有任何问题。 当我尝试使用 silverlight 项目时,在暂存服务器中突然出现 WCF 错误,如下所述:

System.InvalidOperationException ServiceMetadataBehavior的HttpGetEnabled属性设置为true,HttpGetUrl属性是相对地址,但是没有http基地址。要么提供一个 http 基地址,要么将 HttpGetUrl 设置为一个绝对地址。

System.ServiceModel.ServiceActivationException: The service '/ChartsService.svc' cannot be activated due to an exception during compilation.  The exception message is: The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address.  Either supply an http base address or set HttpGetUrl to an absolute address.. ---> System.InvalidOperationException: The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address.  Either supply an http base address or set HttpGetUrl to an absolute address.
   at System.ServiceModel.Description.ServiceMetadataBehavior.CreateHttpGetEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
   at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
   at System.ServiceModel.ServiceHostBase.InitializeRuntime()
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)

Staging 网络服务器正在使用 IIS7.0。 目前我在 web.config 中有以下配置:

<behaviors>
        <serviceBehaviors>
            <behavior name="VATScan.Web.ChartsServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="DemoApp.Web.ChartsServiceBehavior" name="DemoApp.Web.ChartsService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding" contract="DemoApp.Web.IChartsService" />
        </service>
    </services>

令我惊讶的是,它在所有更高的环境中仍然可以正常工作,除了在与上面提到的相同配置的 Staging 中。

谁能帮我解决这个问题?

【问题讨论】:

    标签: wcf silverlight-5.0


    【解决方案1】:

    我已在 web.config 的以下代码中将 httpGetEnabled 修改为 httpsGetEnabled 并解决了问题。

    <behaviors>
            <serviceBehaviors>
                <behavior name="DemoApp.Web.ChartsServiceBehavior">
                    <serviceMetadata httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="DemoApp.Web.ChartsServiceBehavior" name="DemoApp.Web.ChartsService">
                <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServicesBinding" contract="DemoApp.Web.IChartsService" />
            </service>
        </services>
    

    【讨论】:

    • 我想强调一下,在 httpGetEnabled 之前,正确的是 httpsGetEnabled。请注意字母's'
    【解决方案2】:

    上面的答案是一种解决方案,这里是另一种解决方案。

    试试这个:

    <serviceBehaviors>
        <behavior name="VATScan.Web.ChartsServiceBehavior">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="[your service address]" />
            <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
    </serviceBehaviors>
    

    将 [您的服务地址] 替换为“http://localhost:8080/ChartsServiceBehavior”之类的内容

    成功了吗?

    检查这个:https://social.msdn.microsoft.com/Forums/vstudio/en-US/2fd858cb-8988-444f-868c-2ceea9cc9705/httpgetenabled-property?forum=wcf

    【讨论】:

    • 非常感谢您的回复 :)
    【解决方案3】:

    我今天遇到了这个问题,但上述解决方案都不适合我。我通过执行以下操作解决了它。

    检查您尝试打开的“ServiceHost”类型。例如:

    ..
    myServiceHost = new ServiceHost(typeof(CMDataCollector.CMDataService));
    myServiceHost.Open();      //this line was giving the above exception
    ..
    

    “ServiceHost”的类型应该是您配置中的服务名称,如下所示。

          <service name="CMDataCollector.CMDataService">
            <endpoint address="rest" binding="webHttpBinding" contract="CMDataCollector.IRealtimeDataService" behaviorConfiguration="jsonBehavior" />
            <endpoint address="" binding="basicHttpBinding" contract="CMDataCollector.IRealtimeDataService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:9080/TRealtimeData/" />
              </baseAddresses>
            </host>
          </service>
    

    “ServiceHost”的类型和配置中的服务名称应该相同。然后就可以打开“ServiceHost”并启动服务了

    【讨论】:

      【解决方案4】:
      Either supply an HTTP base address or set HttpsGetUrl to an absolute address.
      

      发生此错误是因为设置在逻辑上错误。如果启用 httpGetEnabled 意味着,您允许客户端通过 HTTP 检索元数据(意味着客户端可以获取有关提供的那些方法服务的信息)。如果您不提供 HTTP 的 URL,客户端如何从 HTTP 检索元数据。因此,错误消息会提醒您提供 URL。

      你有三个选择。

      1. 提供 httpGetUrl 作为上面显示的其他答案
      2. 通过 IIS 绑定地址

      1. 将 httpGetEnabled 设置为 false 或某些答案将 httpGetEnabled 修改为 httpsGetEnabled 意味着他们的 IIS 上只有 HTTPS 绑定设置

      【讨论】:

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