【问题标题】:Why does this WCF call fail when passing in a federated security token为什么在传递联合安全令牌时此 WCF 调用失败
【发布时间】:2013-01-30 05:25:42
【问题描述】:

我正在尝试将安全令牌从客户端应用程序传递到 WCF 服务以进行身份​​验证。

对于此示例,我只是使用标准文件、新建 WCF 应用程序项目并尝试调用 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));
}

任何关于我应该检查的事情的指针都会很棒,因为我现在对这个有点不知所措。我不确定如何进一步调试?

【问题讨论】:

    标签: wcf wcf-security wif federated-identity


    【解决方案1】:

    我终于设法克服了这个错误。问题是服务和客户端绑定之间的小错误匹配。

    将我在 web.config 中的绑定更改为此解决了问题

    <bindings>
      <ws2007FederationHttpBinding>
        <binding name ="IdentityServer">
          <security mode="TransportWithMessageCredential">
            <message issuedKeyType="BearerKey" establishSecurityContext="false"/>
          </security>
        </binding>
      </ws2007FederationHttpBinding>
    </bindings>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-22
      • 2011-06-25
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      相关资源
      最近更新 更多