使用basicHttpsBinding通过http和https提供WCF Web服务

时间:2014-10-29 00:32:32

标签: web-services wcf http https

我正在尝试通过http和https提供我的网络服务,但我遇到了这个错误:

A child element named 'endpoint' with same key already exists at the same configuration scope. Collection elements must be unique within the same configuration scope (e.g. the same application.config file). Duplicate key value: 'address:;bindingConfiguration;bindingName:;bindingNamespace:;bindingSectionName:basicHttpsBinding;contractType:RestService.Iservice;kind:;endpointConfiguration:;'.

现在,这是一个明显的错误,但我不知道如何更改我的配置以支持同一合同上的http和https请求。 请注意,我希望使用WCF4.5 basicHttpsBinding配置。

这是我的配置:

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="RestService.service">
<!--
        <host>
          <baseAddresses>
            <add baseAddress = "http://www.nl/service.svc/" />
            <add baseAddress = "https://www.nl/service.svc/" />
          </baseAddresses>
        </host>       
-->
        <endpoint binding="webHttpBinding" contract="RestService.Iservice" />
        <endpoint binding="webHttpBinding" address="" bindingConfiguration="webHttpBindingWithJsonP" name="RestService.Iservice" contract="RestService.Iservice">
        </endpoint>

        <endpoint binding="basicHttpsBinding" contract="RestService.Iservice" />
        <endpoint binding="basicHttpsBinding" address="" name="RestService.Iservice" contract="RestService.Iservice">    
        </endpoint>

      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true">
        </binding>
      </webHttpBinding>
      <basicHttpsBinding>
        <binding name="webHttpsBindingWithJsonP">
          <security mode="Transport"></security>
        </binding>
      </basicHttpsBinding>
    </bindings>
    <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp />
        </behavior>
        <behavior name="webHttpBehavior">
          <webHttp />
        </behavior>

      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

1 个答案:

答案 0 :(得分:1)

在端点中,您需要将Json端点的绑定设置为webHttpBinding,而不是basicHttpBinding。对于安全端点,您需要添加绑定配置并将安全模式设置为transport。

另外,请为Web /基本端点设置地址。我很确定你不能使用具有相同地址的那两个绑定。

最后,由于您是在IIS下托管的,因此可以删除baseAddress部分,因为它不是必需的。并确保IIS中的网站配置为支持http和https协议(通过IIS管理器中的网站绑定对话框检查)