2012-07-03 40 views
3

我試圖放在一起聲稱感知WCF服務和客戶端。無法序列化Saml2AssertionKeyIdentifierClause

我使用的thinktecture Identity Server,我已經通過看「用令牌與WCF/SOAP」例如把一個控制檯客戶端:

var token = GetSecurityToken(); 

var binding = 
    new WS2007FederationHttpBinding(
     WSFederationHttpSecurityMode.TransportWithMessageCredential); 
binding.Security.Message.EstablishSecurityContext = false; 

var factory = 
    new ChannelFactory<IService1>(
     binding, 
     new EndpointAddress("https://localhost:44301/Service1.svc")); 
factory.Credentials.SupportInteractive = false; 

factory.ConfigureChannelFactory(); 

var service = factory.CreateChannelWithIssuedToken(token); 
var result = service.GetData(42); 

我有(什麼樣子)一來自STS的有效令牌。

然而,它拋出在調用GetData異常,如下所示:

有序列化的安全密鑰標識符錯誤。有關更多詳細信息,請參閱 內部例外。

內部異常如下:

令牌串行不能序列 'System.IdentityModel.Tokens.Saml2AssertionKeyIdentifierClause'。 如果這是自定義類型,則必須提供自定義序列化程序。

我能找到的唯一提到的這個問題是this one on the MSDN forums,但這只是稍有關係。

在調試器中看來,端點行爲似乎包含(最終)Saml2SecurityTokenHandler,而其他鏈接暗示的是所有需要的。

我錯過了什麼?

+0

如何將我的答案標記爲接受的答案? –

+0

因爲我不在一個地方去驗證你的答案是否真的有效...... –

回答

0

在您的WCF服務中啓用了WIF嗎?

請確保您有在配置這些設置:

在serviceCredentials行爲 - useIdentityConfiguration =真 在serviceAuthorization行爲 - principalPermissionMode =總是

+0

據我所知,是的。我使用了(VS2012中的新功能)'Identity and Access'工具來配置它。也許我錯過了什麼? –

+0

但是,據我所知(使用WCF跟蹤),請求從來沒有得到那麼遠... –

7

我剛纔當我從升級有完全相同的問題startersts到身份服務器v2並從saml1.1切換到saml2。

我不生成我的代理,所以解決了我的問題是簡單地將Credentials.UseIdentityConfiguration設置爲在我的渠道工廠上爲true。也許這不是默認情況下完成的,如果你生成你的代理?或者,如果您使用自定義的ChannelFactory,那麼您可能忘記像我那樣設置它。

var channelFactory = new ChannelFactory<T>(endpointName); 
channelFactory.Credentials.UseIdentityConfiguration = true; 

var channel = channelFactory.CreateChannelWithIssuedToken(token) 

...使用信道而不繫列化例外現在

希望它能幫助,無需添加客戶端上的一個system.identityModel部分其他討論線程建議。

+0

在你的情況只是factory.Credentials。UseIdentityConfiguration = true; –

+1

factory.Credentials.UseIdentityConfiguration = true; 這對我來說訣竅:-) – StefanHa