2011-07-28 51 views
3

我無法找到我在做什麼錯誤。如何使用引導令牌正確連接到WCF服務

當我嘗試調用服務操作,我得到錯誤:

通信對象,System.ServiceModel.Channels.ServiceChannel,不能用於通信,因爲它是處於故障狀態。

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

嘗試使用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");