获取HTTPS以使用WCF和Windows服务

时间:2012-08-09 08:59:35

标签: windows wcf service https servicehost

我尝试在WF_WCF_Samples \ WCF \ Basic \ Services \ Hosting \ WindowsService \ CS \ WindowsService.sln中更新MS示例应用程序的客户端和服务的App.config文件,以便使用安全绑定但客户端使用时对服务方法的调用抛出异常

“向https:// .... / servicemodelsamples / service发出HTTP请求时发生错误。这可能是由于在HTTPS情况下未使用HTTP.SYS正确配置服务器证书。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。“

内部异常“基础连接已关闭:发送时出现意外错误”

据我所知,服务器和客户端配置都匹配并使用传输安全模式,而mex端点现在使用mexHttpsBinding而不是mexHttpBinding,并且适当地启用了服务行为。

有人可以告诉我什么是遗失或错误的,因为我尝试了许多调整但没有成功?

由于

服务器和客户端配置

    <?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation.  All Rights Reserved.-->
<configuration>

  <system.serviceModel>

    <services>
      <service name="Microsoft.Samples.WindowsService.WcfCalculatorService">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:8000/ServiceModelSamples/service"/>
          </baseAddresses>
        </host>
        <!-- This endpoint is exposed at the base address provided by host: https://localhost:8000/ServiceModelSamples/service -->
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="https" contract="Microsoft.Samples.WindowsService.ICalculator"/>
        <!-- The mex endpoint is exposed at https://localhost:8000/ServiceModelSamples/service/mex -->
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <bindings>
      <basicHttpBinding>
        <!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
        <binding name="https">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <!-- For debugging purposes set the includeExceptionDetailInFaults attribute to true -->
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>
</configuration>

    <?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation.  All Rights Reserved.-->
<configuration>
  <system.serviceModel>

    <client>
      <endpoint name="" address="https://localhost:8000/servicemodelsamples/service" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.Samples.WindowsService.ICalculator"/>
    </client>

    <bindings>
      <basicHttpBinding>
        <!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
        <binding name="Binding1">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

1 个答案:

答案 0 :(得分:0)

mex不能成为https

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>

更改为

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>