2017-09-18 26 views
1

WCF WFサービスにアクセスしようとしたときに、同じ権限でSSL/TLSのセキュリティで保護されたチャネルを確立できませんでした。WCF WFサービス、権限を持つSSL/TLS用のセキュリティで保護されたチャネルを確立できませんでした

私はたくさんのstackoverflow/googleソリューションを試しましたが、これまでのところ運がありません。

証明書を使用して検証する第三者に接続するWCF WFサービスを作成しました。私のWeb.configファイルには、次のようになります。

<?xml version="1.0"?> 
<configuration> 
<appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> 
</appSettings> 
<system.web> 
    <compilation debug="true" strict="false" explicit="true" 
          targetFramework="4.5.1"/> 
    <httpRuntime targetFramework="4.5.1"/> 
</system.web> 
<system.serviceModel> 
    <bindings>  
    <basicHttpsBinding> 
     <binding name="binding1"> 
     <security mode="TransportWithMessageCredential"> 
      <message clientCredentialType="Certificate" /> 
     </security> 
     </binding> 
    </basicHttpsBinding> 
    </bindings> 
    <client> 
    <!-- Test Endpoint --> 
    <endpoint address="https://example.com" 
       behaviorConfiguration="endpointBehavior" 
       binding="basicHttpsBinding" 
       bindingConfiguration="binding1" 
       contract="ContractPortType" 
       name="Port"> 
    </endpoint> 
    </client> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/>   
     </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
     <behavior name="endpointBehavior"> 
     <clientCredentials>   
      <clientCertificate findValue="SOMETHUMBPRINT" 
           storeLocation="LocalMachine" 
           storeName="My" 
           x509FindType="FindByThumbprint" /> 
     </clientCredentials> 
     </behavior> 
    </endpointBehaviors> 
    </behaviors> 
    <protocolMapping> 
    <add binding="basicHttpsBinding" scheme="https"/> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
          multipleSiteBindingsEnabled="true" 
          minFreeMemoryPercentageToActivateService="1"/> 
</system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 

クライアントがこれを実行しているだけのシンプルなコンソールです:

using (var client = new ServiceClient()) 
{ 
    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
    var msg = client.GetData(); 
    Console.WriteLine(msg); 
} 

次のApp.configがあります

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <system.serviceModel> 
    <bindings>  
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService"/> 
     </basicHttpBinding> 
    </bindings> 

    <client> 
     <endpoint address="http://localhost:55670/GetData.xamlx" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService" 
     contract="Reference.IService" name="BasicHttpBinding_IService" behaviorConfiguration="endpointBehavior" /> 
    </client> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="endpointBehavior"> 
      <clientCredentials> 
      <clientCertificate findValue="SOMETHUMBPRINT" 
           storeLocation="LocalMachine" 
           storeName="My" 
           x509FindType="FindByThumbprint" /> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

誰かが私を助けることができれば素晴らしいだろう。

EDIT: 私は働くことができないことは、私のWCF WFサービスとthirdpartyサービスの間に必要なSSL接続です。クライアントからthirdpartyサービスを直接呼び出すと、System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12を設定できます。 私はWCF WFサービスで同じことをする方法を見つけることができません。

編集: だから私はそれを動作を作成してから、そのアクティビティを呼び出してからthirdpartyアクティビティを呼び出してから動作させることで動作させることができますが、より良い方法が必要です。

public sealed class SetTlsVersion : CodeActivity 
{ 
    protected override void Execute(CodeActivityContext context) 
    { 
     System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
    } 
} 
+0

あなたは(svctraceviewer.exe)をトレースWCFを使用してみましたか? https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/index – Yaniv

+0

@Yaniv私はそれを見てくれます。チップのおかげで – e11en

+0

@ Yanivはトレースを使って賢くなっていませんすべてのエラーは同じです "権限を持つSSL/TLSのセキュリティで保護されたチャネルを確立できませんでした" – e11en

答えて

0

私がこの種のいいことをすることができた唯一の方法は、HttpModule(チップにはajawad987に感謝)でした。私はまだこれがWeb.configでしかできない(またはすべきである)と確信しています。

public class InitializerModule : IHttpModule 
{ 
    public void Dispose() { } 

    public void Init(HttpApplication context) 
    { 
     // Sets the TLS version for every request made to an external party 
     System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
    } 
} 

のWeb.config

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
    <add name="InitializerModule" type="WorkflowService.Helpers.InitializerModule"/> 
    </modules> 
</system.webServer> 
2

今年も同様の問題が発生しましたが、一部のSSL証明書でTLS 1.2が使用されていることが判明しました。

.NET 4.5では、TLSバージョンがv1.1にデフォルト設定されています。これは、次のコードで、あなたのコードに変更することができます。

using System.Net; 
// ... 
// In your application startup flow, set the security protocol to TLS 1.2. 
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 

は、上記の理想的なアプリケーションの起動時に起動する必要があります。その後、私はあなたが行くのが良いと思う。

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; 

と.NET 3.5と下位で、TLS 1.2がさえ、残念ながらサポートされていません。 .NET 4.0対象アプリケーションTLSのバージョンを設定するためにわずかに異なるトリックが必要になります:

サイドノート

。しかし、あなたの場合、それはあなたのこのような前進にあなたの良いので、あなたのターゲット.NET 4.5のように見えます。

EDIT:お客様のクライアントコードスニペットで、TLSバージョンをビット単位でORしたことがわかりましたが、これは間違っています。この場合は、単一の値SecurityProtocolType.Tls12にする必要があります。

基本的な.NET Frameworkネットワークコードは、最後にSecurityProtocolType.Tlsしか使用していないと仮定していますが、SSL/TLS証明書がサポートするものと一致しません。

うまくいけば助けてください。

+0

私はクライアントを呼び出すとこれをすでに追加しています(クライアントコード参照)。私はコンソールから直接thirdpartyにアクセスすると動作しますが、ワークフローサービスからthirdpartyを呼び出すと、このエラーが発生します。私はWCF WFサービスでセキュリティプロトコルを設定する方法を見つけることができません。 – e11en

+0

TLSバージョンbtwに関するヒントをありがとう! – e11en

+0

私はあなたのポストをもう少し徹底的に読むべきだった。私はまだ方法が見つかりませんでしたが、おそらく適切なTLSレベルを設定するHTTPモジュールを持つことができます。 WCFサービスの前に呼び出されます。実際には、それを設定するサービス動作を作成します。 – ajawad987

関連する問題

 関連する問題