如何使用引导令牌正确连接到WCF服务

时间:2011-07-28 12:04:12

标签: .net wcf wif

我找不到我做错了什么。

当我尝试调用服务操作时,我收到错误:

通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态。

    using (Ref.SService_V1_0Client client = new Ref.SService_V1_0Client("RWS"))
{
    var request = new Ref.IVISRequestStructure();
    request.Header = new Ref.RequestHeaderStructure();


    client.ChannelFactory.Credentials.SupportInteractive = false;
    ChannelFactoryOperations.ConfigureChannelFactory(client.ChannelFactory);
    ChannelFactoryOperations.CreateChannelWithIssuedToken<Ref.ISService_V1_0>(client.ChannelFactory, ((Microsoft.IdentityModel.Claims.ClaimsIdentity)(Page.User.Identity)).BootstrapToken);
    client.StartTransaction("string argument");
}

在web.config中配置:

 <system.serviceModel>
  <bindings>
    <ws2007FederationHttpBinding>
      <binding name="ws2007FederationUserName" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" maxReceivedMessageSize="100000000">
        <security mode="TransportWithMessageCredential">
          <message issuedKeyType="SymmetricKey" negotiateServiceCredential="true">
            <issuer address="adress/STS/Issue.svc/trust/13/issuedtokenmixedsymmetricbasic256" binding="customBinding" bindingConfiguration="issuedtokenmixedsymmetricbasic256"/>
          </message>
        </security>
      </binding>
    </ws2007FederationHttpBinding>
  </bindings>
  <client>
    <endpoint address="another_address/servicename.svc/ws2007Federation"
      binding="ws2007FederationHttpBinding" bindingConfiguration="ws2007FederationUserName"
      contract="Ref.ISService_V1_0" name="RWS" />
  </client>
 </system.serviceModel>

1 个答案:

答案 0 :(得分:1)

尝试使用CreateChannelWithIssuedToken调用的返回值来调用服务,而不是使用客户端变量。请参阅CreateChannel code in this sample for how CreateChannelWithIssuedToken is used.它看起来像这样:

var serviceClient = ChannelFactoryOperations.CreateChannelWithIssuedToken<Ref.ISService_V1_0>(client.ChannelFactory, ((Microsoft.IdentityModel.Claims.ClaimsIdentity)(Page.User.Identity)).BootstrapToken);
serviceClient.StartTransaction("string argument");