【问题标题】:WCF basicHttpsBinding warning: "is invalid according to its datatype"WCF basicHttpsBinding 警告:“根据其数据类型无效”
【发布时间】:2013-02-07 22:45:30
【问题描述】:

我创建了一个 WCF 应用程序,从 basicHttpBinding 开始。在 app.config 中,我配置了以下端点:

<endpoint address="" binding="basicHttpBinding" contract="JMMEcommerceService.IJMMEcommerceService">
  <identity>
    <dns value="localhost" />
  </identity>
</endpoint>

这构建得很好。但是,我想将协议从 HTTP 更改为 HTTPS。如果我将端点声明更改为:

<endpoint address="" binding="basicHttpsBinding" contract="JMMEcommerceService.IJMMEcommerceService">
  <identity>
    <dns value="localhost" />
  </identity>
</endpoint>

(注意:唯一的变化是 basicHttpBinding -> basicHttpsBinding)

我在构建时间收到以下警告:

WCF configuration validation warning: The 'binding' attribute is invalid - The value 'basicHttpsBinding' is invalid according to its datatype 'serviceBindingType'.

为什么我会收到此警告?我还有什么需要改变的吗?

这是完整的 app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="JMMEcommerceService.JMMEcommerceService">
        <endpoint address="" binding="basicHttpsBinding" contract="JMMEcommerceService.IJMMEcommerceService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:8733/Design_Time_Addresses/JMMEcommerceService/JMMEcommerceService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

【问题讨论】:

    标签: wcf wcf-binding wcf-endpoint


    【解决方案1】:

    basicHttpsBinding 似乎不存在于 .NET 4.0 中,仅存在于 4.5 中。您的目标是哪个版本的 .NET?

    【讨论】:

    • 您是否在 IIS 中托管?网站上配置了哪个 .NET 版本?
    • 不,不是 IIS。这一切都在运行 Windows 8 和 VS 2012 Pro 的开发机器上,所以它肯定配置了 .NET 4.5。同样,警告发生在构建时间。
    • 你能发布 web.config 吗?简化了吗?
    • 它不是一个网络应用程序。我已将完整的 app.config 添加到我的原始帖子中。
    【解决方案2】:

    如果您想为您的服务启用 HTTPS,但不为您的元数据启用 HTTPS,您必须为基于 HTTP 的元数据交换端点提供另一个基地址。

    <baseAddresses>
      <add baseAddress="https://localhost:8733/Design_Time_Addresses/JMMEcommerceService/JMMEcommerceService/" />
      <add baseAddress="http://localhost:8734/Design_Time_Addresses/JMMEcommerceService/JMMEcommerceService/" />
    </baseAddresses>
    

    请注意,您还必须分配另一个端口 (8734)。两个协议不能使用同一个端口!

    PS:别忘了给8733端口分配正确的证书

    【讨论】:

    • 虽然这个代码块可能会回答这个问题,但最好能稍微解释一下为什么会这样。
    猜你喜欢
    • 1970-01-01
    • 2018-07-22
    • 2017-02-26
    • 1970-01-01
    • 2021-10-07
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    相关资源
    最近更新 更多