如何将以下wsHttpBinding转换为customBinding?我需要这样,所以我可以增加时钟偏差。这是针对http。
<wsHttpBinding>
<binding name="wsHttpSecurityOptions" maxReceivedMessageSize="10485760" maxBufferPoolSize="524288">
<security mode="Message">
<message clientCredentialType="UserName" establishSecurityContext="true" negotiateServiceCredential="true"/>
<transport clientCredentialType="Certificate" proxyCredentialType="None"/>
</security>
<readerQuotas maxStringContentLength="500000"/>
</binding>
</wsHttpBinding>
我的尝试(如下所示)失败,并显示错误消息“无法找到与绑定CustomBinding的端点的方案https匹配的基址”,但我看不出如何配置UserName消息模式安全性。
<customBinding>
<binding name="wsHttpSecurityOptions">
<transactionFlow />
<security authenticationMode="UserNameForSslNegotiated">
<secureConversationBootstrap authenticationMode="UserNameForSslNegotiated">
<localServiceSettings maxClockSkew="00:10:00" />
</secureConversationBootstrap>
<localServiceSettings maxClockSkew="00:10:00" />
</security>
<textMessageEncoding>
<readerQuotas maxStringContentLength="500000"/>
</textMessageEncoding>
<httpsTransport maxReceivedMessageSize="10485760" maxBufferPoolSize="524288" />
</binding>
</customBinding>
答案 0 :(得分:16)
经过一番搜索后,我发现Yaron Naveh的cool tool进行了转换,产生了以下内容(我在时钟偏差中加入了)
<customBinding>
<binding name="wsHttpSecurityOptions">
<transactionFlow />
<security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<localServiceSettings maxClockSkew="00:10:00" />
</secureConversationBootstrap>
<localServiceSettings maxClockSkew="00:10:00" />
</security>
<textMessageEncoding />
<httpTransport maxBufferSize="10485760" maxReceivedMessageSize="10485760" />
</binding>
</customBinding>
再次感谢Yaron,我希望在找到另一个问题之前我已经找到了它,我问了这个问题后我自己回答了50分钟(这是我的记录:))
答案 1 :(得分:0)
检查此解决方案。它通过代码创建自定义绑定,mofifies其时钟偏差,并将其设置为要使用的绑定。 (来源:http://sandrinodimattia.net/blog/posts/wcf-and-fixing-clienthost-time-issues-maxclockskew-quickly/)
ServiceHost service = new ServiceHost(typeof(Calculator));
Binding currentBinding = service.Description.Endpoints[0].Binding;
// Set the maximum difference in minutes
int maxDifference = 300;
// Create a custom binding based on an existing binding
CustomBinding myCustomBinding = new CustomBinding(currentBinding);
// Set the maxClockSkew
var security = myCustomBinding.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
security.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
// Set the maxClockSkew
var secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
var bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
bootstrap.LocalServiceSettings.MaxClockSkew = TimeSpan.FromMinutes(maxDifference);
// Update the binding of the endpoint
service.Description.Endpoints[0].Binding = myCustomBinding;