2012-04-23 22 views
1

私はWCFのbasicHttpBindingでhttpsを動作させようとしています。サービスは正常に動作しているようですが、クライアントを実行しようとしたときにサービスのメソッドの1つを呼び出すと、次の例外が発生します。WCFのbasicHttpBinding経由のhttps

SSL/TLSの信頼関係を確立できませんでした権限 'sfs-111:20023'を持つチャンネル。

下記のコードと設定ファイルが含まれています。誰かが助けることができたら、私はとても感謝しています。

私はWCFを初めて使いました。

ここに私のサービスはApp.configファイル'S:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 

    <!-- DEBUG - TURN ON TRACING --> 
    <system.diagnostics> 
     <sources> 
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> 
       <listeners> 
        <add name="traceListener" 
          type="System.Diagnostics.XmlWriterTraceListener" 
          initializeData= "c:\tahseen\dd\WCFServer.svclog" /> 
       </listeners> 
      </source> 
     </sources> 
    </system.diagnostics> 

    <system.serviceModel> 
     <behaviors> 
      <serviceBehaviors> 

       <!-- BEHAVIOR FOR META DATA --> 
       <behavior name="DeltaServiceBehavior"> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceCredentials> 
         <windowsAuthentication includeWindowsGroups="false" allowAnonymousLogons="false" /> 
        </serviceCredentials> 
        <dataContractSerializer maxItemsInObjectGraph="100000000" /> 
       </behavior> 

       <!-- BEHAVIOR FOR TRANSPORT SECURITY --> 
       <behavior name="SecureBehavior"> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceCredentials> 
         <clientCertificate> 
          <authentication certificateValidationMode="PeerTrust" /> 
         </clientCertificate> 
         <serviceCertificate findValue="sfs-Test" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" /> 
        </serviceCredentials> 
        <dataContractSerializer maxItemsInObjectGraph="100000000" /> 
       </behavior> 

      </serviceBehaviors> 
     </behaviors> 

     <bindings> 

      <!-- DEFINE BINDING --> 
      <basicHttpBinding> 
       <binding name="HttpBinding_AlphaSystem"> 
        <security mode="Transport"> 
         <transport clientCredentialType="Certificate" /> 
        </security> 
       </binding> 
      </basicHttpBinding> 

     </bindings>   
     <services> 

      <!-- DEFINE SERVICE --> 
      <service behaviorConfiguration="SecureBehavior" name="Alpha.Services.DeltaService.DeltaService"> 

       <!-- ENDPOINT FOR METADATA --> 
       <endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /> 

       <!-- ENDPOINT FOR DATA --> 
       <endpoint address="" binding="basicHttpBinding" bindingConfiguration="HttpBinding_AlphaSystem" contract="Alpha.Services.DeltaService.IDeltaService"/>      

       <!-- BASE ADDRESSES FOR SERVICE--> 
       <host> 
        <baseAddresses> 
         <add baseAddress="http://SFS-111:20022/DeltaService" /> 
         <add baseAddress="https://SFS-111:20023/DeltaService" /> 
        </baseAddresses> 
       </host> 
      </service> 

     </services> 
    </system.serviceModel> 
</configuration> 

ここでは私のクライアントのapp.configです:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.diagnostics> 
     <sources> 
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> 
       <listeners> 
        <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\tahseen\dd\WCFClient.svclog" /> 
       </listeners> 
      </source> 
     </sources> 
    </system.diagnostics> 

    <system.serviceModel> 

     <!-- DEFINE SECURE BEHAVIOR --> 
     <behaviors> 
      <endpointBehaviors> 
       <behavior name="ClientBehavior"> 
        <clientCredentials> 
         <clientCertificate findValue="sfs-Client" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" /> 
         <serviceCertificate> 
          <authentication certificateValidationMode="PeerTrust"/> 
         </serviceCertificate> 
        </clientCredentials> 
       </behavior> 
      </endpointBehaviors> 
     </behaviors> 

     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IDeltaService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01: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="Transport"> 
         <transport clientCredentialType="Certificate" realm="" /> 
        </security> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://sfs-111:20023/DeltaService" binding="basicHttpBinding" behaviorConfiguration ="ClientBehavior" 
       bindingConfiguration="BasicHttpBinding_IDeltaService" contract="DeltaService.IDeltaService" 
       name="BasicHttpBinding_IDeltaService"> 
       <identity> 
        <dns value="sfs-Test" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

は、ここに私のサービスコード'S:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.ServiceModel.Description; 

namespace Alpha.Services.DeltaService 
{ 
    public class DeltaService : IDeltaService 
    { 
     public int timesTwo(int n) 
     { 
      return n * 2; 
     } 
    } 

    [ServiceContract] 
    interface IDeltaService 
    { 
     [OperationContract] 
     int timesTwo(int n); 
    } 

    public class App 
    { 
     public static void Main(string[] args) 
     { 
      //DeltaService service = new DeltaService(); 
      ServiceHost serviceHost = new ServiceHost(typeof(DeltaService)); 
      serviceHost.Open(); 

      Console.WriteLine("Press any key to exit"); 
      Console.ReadKey(); 

      serviceHost.Close(); 
     } 
    } 
} 

ここに私のクライアントコードは次のとおりです。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace WCFClient 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      DeltaService.IDeltaService service = new DeltaService.DeltaServiceClient(); 

      int result = service.timesTwo(5); 

      Console.WriteLine(result); 
     } 
    } 
} 
+1

は同じマシン上で実行されているこれらのテストはありますか? Windows証明書ストアで証明書が正しく構成されていますか?これらのPeerTrust設定は、HTTPSがWindowsオペレーティングシステムによって直接処理されるため、HTTPSでは機能しません。 –

+0

証明書が正しく設定されているかどうかを確認するにはどうすればよいですか?また、PeerTrustがうまくいかない場合は、どうすれば変更できますか?私がWCFと証明書を初めて使うので、私の無知を許してください。 – user1229458

+0

これらの証明書は自己署名されていますか? –

答えて

2

ちょうどテストのために、クライアント上でSSL検証を無効にしよう:

http://webservices20.blogspot.com/2008/12/wcf-gotcha-disabling-ssl-validation.html

using System.Net; 
using System.Net.Security; 
using System.Security.Cryptography.X509Certificates; 
... 
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidationCallback); 
... 
public static bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors) 
{ 
return true; 
} 
+0

多分私は何かが欠けているかもしれませんが、これは運動の全ポイントを打ち負かすものではありませんか?どのようにssl検証を無効にすることなく動作させるには? – user1229458

+0

これは、問題が実際に証明書の有効期間であるかどうか、またはその他の問題があるかどうかを判断するのに役立ちます。前者の場合は、信頼できる認証局に証明書発行者x.509をインストールする必要があります –

関連する問題