1

我创建了一个 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>
4

2 回答 2

2

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

于 2013-02-07T22:52:49.553 回答
0

如果您想为您的服务启用 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端口分配正确的证书

于 2014-06-24T12:58:38.710 回答