使用SSL和证书设置WCF的配置文件

使用SSL和证书设置WCF的配置文件,wcf,web-services,binding,ssl,wcf-binding,Wcf,Web Services,Binding,Ssl,Wcf Binding,我正在尝试使用SSL在IIS7中设置WCF Web服务,但对配置文件有点迷茫。 我希望从服务器到客户机的数据被篡改(使用SSL就足够了吗?) 客户机还需要通过证书向服务器标识自己 本人持有以下证书: dev.test.com-访问url表明存在此有效证书 TestServer-标识服务器的虚拟证书(我真的需要这个吗?或者我可以重用dev.test.com?可能有server.test.com?) TestClient-客户端上的虚拟证书 下面是我的配置文件的设置方式: Web.config(

我正在尝试使用SSL在IIS7中设置WCF Web服务,但对配置文件有点迷茫。 我希望从服务器到客户机的数据被篡改(使用SSL就足够了吗?) 客户机还需要通过证书向服务器标识自己

本人持有以下证书:

  • dev.test.com-访问url表明存在此有效证书
  • TestServer-标识服务器的虚拟证书(我真的需要这个吗?或者我可以重用dev.test.com?可能有server.test.com?)
  • TestClient-客户端上的虚拟证书
下面是我的配置文件的设置方式:

Web.config(服务器):

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding"
             messageEncoding="Mtom">
      <security mode="Message">
        <transport clientCredentialType="None" />
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<services>
  <service
    name="TestService"
    behaviorConfiguration="TestServiceBehavior">
    <endpoint
      name="TestEndPoint"
      address=""
      binding="wsHttpBinding"
      bindingConfiguration="wsHttpEndpointBinding"
      bindingNamespace="http://www.example.com/"
      contract="iWebService">
      <!--<identity>
        <dns value=""/>
      </identity>-->
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding"  bindingConfiguration="" name="MexHttpsBindingEndpoint" contract="IMetadataExchange"/>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="TestServiceBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
      <serviceCredentials>
        <clientCertificate>
          <authentication certificateValidationMode="PeerOrChainTrust" />
        </clientCertificate>
        <serviceCertificate findValue="TestServer" storeLocation="LocalMachine"
          storeName="My" x509FindType="FindBySubjectName" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding" bypassProxyOnLocal="false"
      transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
      allowCookies="false">
      <reliableSession ordered="true"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Certificate" negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="TestEndPoint" bypassProxyOnLocal="false"
      transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      messageEncoding="Mtom"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <reliableSession ordered="true"
        enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Certificate" negotiateServiceCredential="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<client>
  <endpoint address="https://dev.test.com/TestService.svc"
    behaviorConfiguration="TestServiceBehavior"
    binding="wsHttpBinding" bindingConfiguration="wsHttpBinding"
    contract="IContractName" name="wsHttpBinding">
    <identity>
      <dns value="TestServer" />
    </identity>
  </endpoint>
  <endpoint address="https://dev.test.com/DistributionCenterService.svc"
    binding="wsHttpBinding" bindingConfiguration="TestEndPoint" contract="IContract.Name"
    name="TestEndPoint" />
</client>

<behaviors>
  <endpointBehaviors>
    <behavior name="TestServiceBehavior">
      <clientCredentials>
        <clientCertificate findValue="TestClient"
                           storeName="My"
                           storeLocation="CurrentUser"
                           x509FindType="FindBySubjectName"/>
        <serviceCertificate>
          <authentication
            certificateValidationMode="PeerOrChainTrust"
            revocationMode="NoCheck"
            trustedStoreLocation="CurrentUser"/>
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

,我得到了
找不到与绑定为WSHttpBinding的终结点的方案http匹配的基址。注册的基址方案是[https]。


无论如何,我真的不知道我应该使用什么配置设置。

我相信要让您能够使用https,客户端的wsHttpBinding上的安全模式需要是Transport或(可能在您的情况下)TransportWithMessageCredential。

我相信您能够使用https,客户端的wsHttpBinding上的安全模式需要是Transport或TransportWithMessageCredential(可能在您的情况下)TransportWithMessageCredential。

仅用于客户端?服务器端呢?也许也有-我关注的是你得到的第一个错误:)太棒了!这就解决了!必须在服务器端和客户端都使用TransportWithMessageCredential。仅用于客户端?服务器端呢?也许也有-我关注的是你得到的第一个错误:)太棒了!这就解决了!必须在服务器端和客户端使用TransportWithMessageCredential。