1

私がやろうとしているのは、別のサーバー上のサービスへの呼び出しをセットアップすることです。これまでのところ..プロキシを作成し、構成情報を取得しました。

私が見つけるのに苦労しているのは、セキュリティを設定する方法です。メッセージ セキュリティとクライアント証明書を使用しています。

これが私のapp.configファイルです..これまでに持っているものです。セキュリティの設定に関する情報は役に立ちます。私が遭遇したほとんどの例は、サービスのセットアップとホスティング側でのセキュリティ保護に関係しています。

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="CCaRWebServiceSoap11Binding" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="01:00:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
        <customBinding>
            <binding name="CCaRWebServiceSoap12Binding">
                <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                    messageVersion="Soap12" writeEncoding="utf-8">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>
                <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                    maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                    realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                    useDefaultWebProxy="true" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="serviceEndpoint1address/"
            binding="basicHttpBinding" bindingConfiguration="CCaRWebServiceSoap11Binding"
            contract="CCaRWebServicePortType" name="CCaRWebServiceHttpSoap11Endpoint" />
        <endpoint address="serviceEndpoint2address/"
            binding="customBinding" bindingConfiguration="CCaRWebServiceSoap12Binding"
            contract="CCaRWebServicePortType" name="CCaRWebServiceHttpSoap12Endpoint" />
    </client>
</system.serviceModel>

私はこのプロジェクトに放り込まれたようなものだったので、WCF は私にとってはなじみのないものです。

4

1 に答える 1

2

プロジェクトにサービス参照がありますか? あなたのサービスは WSDL でセキュリティ記述を提供していますか? 両方の質問の答えが正しい場合は、サービス参照を更新するだけで構成がセキュア モードに変更されます (運が良ければ)。

あなたにとってメッセージセキュリティとは実際には何を意味しますか? メッセージ セキュリティは、メッセージの暗号化と署名も意味します。メッセージ セキュリティは、Basic Http Binding ではサポートされていません。カスタム バインドの場合、次の構成から開始できます。

<customBinding> 
  <binding name="CCaRWebServiceSoap12Binding"> 
    <security authenticationMode="MutualCertificate" /> 
    <!-- there is plenty other configuration attributes in security element - 
         you simply have to know what you need -->
    ...
  </binding>
</customBinding>

これにより、サービスとクライアントの相互証明書認証 (非対称セキュリティを使用) が設定されます。サービス証明書と秘密鍵付きのクライアント証明書 (サービス プロバイダーから提供) が必要です。これらの証明書を証明書ストアにインポートする必要があります。クライアント アプリケーションを実行しているアカウントは、クライアント証明書の秘密キーにアクセスできる必要があります (証明書をユーザーの個人ストアに配置する場合は自動的にアクセスする必要があります)。

これらの証明書をエンドポイントの動作に設定するよりも:

<behaviors>
  <endpointBehaviors>
    <behavior name="clientBehavior">
      <clientCredentials>
        <clientCertificate findValue="..." storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" /> 
        <serviceCertificate>
          <defaultCertificate findValue="..." storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName" />
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

エンドポイントでは、次の動作を参照します。

<endpoint address="serviceEndpoint2address/" binding="customBinding" 
  bindingConfiguration="CCaRWebServiceSoap12Binding"        
  contract="CCaRWebServicePortType" name="CCaRWebServiceHttpSoap12Endpoint"
  behaviorConfiguration="clientBehavior" />

これらの証明書は、プロキシ インスタンスのコードから設定することもできます。

これは多くの設定の 1 つにすぎないことに注意してください。「そのまま」でうまくいくとは言いません。証明書を使用してメッセージ セキュリティを設定するのは、特に WSDL にセキュリティの記述がない場合や、サービスが WCF で記述されていない場合は注意が必要です。

MSDNでこの記事を確認することもできます。また、クライアントを構成します。

于 2010-09-16T19:53:14.620 に答える