Udostępnij przez


<message> z <basicHttpBinding>

Definiuje ustawienia zabezpieczeń na poziomie komunikatów w warstwie PodstawowaHttpBinding<>.

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding>
          <security>
            <message>

Składnia

<message algorithmSuite="Basic128/Basic192/Basic256/Basic128Rsa15/Basic256Rsa15/TripleDes/TripleDesRsa15/Basic128Sha256/Basic192Sha256/TripleDesSha256/Basic128Sha256Rsa15/Basic192Sha256Rsa15/Basic256Sha256Rsa15/TripleDesSha256Rsa15"
         clientCredentialType="UserName/Certificate" />

Atrybuty i elementy

W poniższych sekcjach opisano atrybuty, elementy podrzędne i elementy nadrzędne

Attributes

Attribute Description
algorithmSuite Ustawia algorytmy szyfrowania komunikatów i zawijania klucza. Ten atrybut jest typu SecurityAlgorithmSuite, który określa algorytmy i rozmiary kluczy. Te algorytmy są mapować na określone w specyfikacji języka zasad zabezpieczeń (WS-SecurityPolicy).

Domyślna wartość to Basic256.
Clientcredentialtype Określa typ poświadczenia, który ma być używany podczas uwierzytelniania klienta przy użyciu zabezpieczeń opartych na komunikatach. Wartość domyślna to UserName.

clientCredentialType, atrybut

Wartość Description
Nazwa użytkownika — Wymaga uwierzytelnienia klienta na serwerze przy użyciu poświadczeń UserName. To poświadczenie należy określić przy użyciu elementu< clientCredentials>.
— Program WCF nie obsługuje wysyłania skrótu hasła lub wyprowadzania kluczy przy użyciu haseł i używania takich kluczy w celu zabezpieczenia komunikatów. W związku z tym program WCF wymusza zabezpieczenie transportu podczas korzystania z poświadczeń UserName. W przypadku programu basicHttpBindingwymaga to skonfigurowania kanału SSL.
Certificate Wymaga uwierzytelnienia klienta na serwerze przy użyciu certyfikatu. W tym przypadku należy określić poświadczenia klienta przy użyciu <parametrów clientCredentials> i <clientCertificate>. Ponadto w przypadku korzystania z trybu zabezpieczeń komunikatów klient musi być aprowizowany przy użyciu certyfikatu usługi. W tym przypadku należy określić poświadczenie usługi przy użyciu ClientCredentials klasy lub ClientCredentials elementu zachowania i określić certyfikat usługi przy użyciu <elementu serviceCertificate>.

Elementy podrzędne

Żaden

Elementy nadrzędne

Składnik Description
<bezpieczeństwo> Definiuje możliwości zabezpieczeń podstawowychHttpBinding<>.

Example

W tym przykładzie pokazano, jak zaimplementować aplikację korzystającą z podstawowych zabezpieczeńHttpBinding i komunikatów. W poniższym przykładzie konfiguracji dla usługi definicja punktu końcowego określa podstawoweHttpBinding i odwołuje się do konfiguracji powiązania o nazwie Binding1. Certyfikat używany przez usługę do uwierzytelniania się na kliencie jest ustawiany w behaviors sekcji pliku konfiguracji w serviceCredentials ramach elementu . Tryb weryfikacji stosowany do certyfikatu używanego przez klienta do uwierzytelniania się w usłudze jest również ustawiany w behaviors sekcji w obszarze elementu clientCertificate .

Te same szczegóły powiązania i zabezpieczeń są określone w pliku konfiguracji klienta.

<system.serviceModel>
  <services>
    <service name="Microsoft.ServiceModel.Samples.CalculatorService"
             behaviorConfiguration="CalculatorServiceBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
        </baseAddresses>
      </host>
      <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service -->
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="Binding1"
                contract="Microsoft.ServiceModel.Samples.ICalculator" />
      <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>
  <bindings>
    <basicHttpBinding>
    <!-- This configuration defines the SecurityMode as Message and
         the clientCredentialType as Certificate. -->
      <binding name="Binding1">
        <security mode = "Message">
          <message clientCredentialType="Certificate" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
  <behaviors>
    <serviceBehaviors>
      <behavior name="CalculatorServiceBehavior">
        <serviceMetadata httpGetEnabled="True" />
        <serviceDebug includeExceptionDetailInFaults="False" />
        <!-- The serviceCredentials behavior allows one to define a service certificate.
             A service certificate is used by a client to authenticate the service and provide message protection.
             This configuration references the "localhost" certificate installed during the setup instructions. -->
        <serviceCredentials>
          <serviceCertificate findValue="localhost"
                              storeLocation="LocalMachine"
                              storeName="My"
                              x509FindType="FindBySubjectName" />
          <clientCertificate>
            <!-- Setting the certificateValidationMode to PeerOrChainTrust means that if the certificate
               is in the user's Trusted People store, then it will be trusted without performing a
               validation of the certificate's issuer chain. This setting is used here for convenience so that the
               sample can be run without having to have certificates issued by a certification authority (CA).
               This setting is less secure than the default, ChainTrust. The security implications of this
               setting should be carefully considered before using PeerOrChainTrust in production code. -->
            <authentication certificateValidationMode="PeerOrChainTrust" />
          </clientCertificate>
        </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

Zobacz także