3

認証のために、クライアントアプリケーションからWCFサービスにセキュリティトークンを渡そうとしています。

この例では、標準のFile、New WCF Applicationプロジェクトを使用して、GetDataメソッドを呼び出そうとしています。

クライアントで次の例外が発生します

{"メッセージを処理できませんでした。これは、アクション' http://tempuri.org/IService1/GetData 'が正しくないか、メッセージに無効または期限切れのセキュリティコンテキストトークンが含まれているか、間に不一致があることが原因である可能性があります。バインディング。サービスが非アクティブのためにチャネルを中止した場合、セキュリティコンテキストトークンは無効になります。サービスがアイドルセッションを途中で中止しないようにするには、サービスエンドポイントのバインディングの受信タイムアウトを早めに増やします。 "}

WCFサービスでトレースを有効にすると、次のエラーが表示されます

アクション' http://tempuri.org/IService1/GetData 'でメッセージを受け入れることができるチャネルはありませんでした。

私のサービスのWeb.Configは次のようになります

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />        
  </configSections>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>

  <!--Configure STS-->
  <system.identityModel>
    <identityConfiguration>
      <audienceUris>
        <add value="https://stsserver.security.int/myApp" />
      </audienceUris>
      <issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089">
        <trustedIssuers>
          <add thumbprint="‎3c8fc34bd483b07ba0d1509827fc4788c36247e4" name="StartSSL Login" />
        </trustedIssuers>
      </issuerNameRegistry>
      <certificateValidation certificateValidationMode="None"/>
    </identityConfiguration>
  </system.identityModel>

  <system.serviceModel>
    <bindings>
      <ws2007FederationHttpBinding>
        <binding name ="IdentityServer">
          <security mode="TransportWithMessageCredential">
          </security>
        </binding>
      </ws2007FederationHttpBinding>
    </bindings>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="Services.Service1" behaviorConfiguration="CertificateBehavior">
        <endpoint name="ws" binding="ws2007FederationHttpBinding" bindingConfiguration="IdentityServer" contract="Services.IService1" address=""/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="CertificateBehavior">
          <serviceCredentials>
            <serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>    
</configuration>

このWCFサービスを呼び出すクライアントアプリケーションのメソッドは次のようになります

static void CallSecuredService(SecurityToken samlToken)
{
    var binding = new WS2007FederationHttpBinding((WSFederationHttpSecurityMode.TransportWithMessageCredential));
    binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;
    binding.Security.Message.EstablishSecurityContext = false;

    var factory = new ChannelFactory<IService1>(binding, new EndpointAddress("https://localhost/myservice/Service1.svc"));
    factory.Credentials.SupportInteractive = false;
    factory.Credentials.UseIdentityConfiguration = true;
    var proxy = factory.CreateChannelWithIssuedToken(samlToken);

    Console.WriteLine(proxy.GetData(1));
}

私が今これに少し戸惑っているので、私がチェックしなければならないことについてのどんなポインタも素晴らしいでしょう。これをさらにデバッグする方法がわかりませんか?

4

1 に答える 1

2

私はついにこのエラーを乗り越えることができました。問題は、サービスとクライアントのバインディング間の小さなミスマッチでした。

web.configのバインディングをこれに変更すると、問題が修正されました

<bindings>
  <ws2007FederationHttpBinding>
    <binding name ="IdentityServer">
      <security mode="TransportWithMessageCredential">
        <message issuedKeyType="BearerKey" establishSecurityContext="false"/>
      </security>
    </binding>
  </ws2007FederationHttpBinding>
</bindings>
于 2013-02-15T10:41:39.447 に答える