WCF自定义绑定,这将支持HTTPS,一个签名证书和签名的用户名令牌令牌、自定义、这将、绑定

2023-09-03 15:06:15 作者:acacia(相思)

我试着问this问题有关的WCF,但我没有得到回应,所以我再次一个更集中的问题尝试。

I've tried asking this question about WCF but I've got no answers so I'm trying again with a more focused question.

谁能告诉我如何创建一个自定义的WCF客户端绑定将:

Can anyone tell me how to create a custom binding for a WCF client that will:

在包括签名的用户名令牌 在包括签名的邮件 将通过HTTPS发送

更新

不知道,如果它使但我使用.NET 4

Not sure if it makes a difference but I'm using .NET 4

另一个更新

如果任何人有这将是真棒任何具体的实例

If anyone has any specific examples that would be awesome

推荐答案

我想我可以给一些指点。你将不得不使用WIF得到这个工作。要通过用户​​名令牌将是签署一个SAML令牌。要生成SAML令牌,有自带的WCF样品STS示例项目,您可以使用该示例项目。您的code应该是这个样子:

I think i can give some pointers. You will have to use WIF to get this working. The username token which you want to pass would be a SAML token that is signed. To generate the SAML token, there is a STS sample project that comes with WCF sample, you can use that sample project. Your code should look something like this:

            //This class will use the STS WCF sample to generate the signed SAML token
            var tm = new TokenManager();
            var samlToken = tm.GetSamlToken(Username);
            var cf2 = new ChannelFactory<IPingService>("WcfSamlOverMutualSsl");
            cf2.Credentials.ClientCertificate.Certificate = clientCert;

            cf2.ConfigureChannelFactory();

            cf2.Open();
            // this code will attach the SAML token to WCF service.
            var proxy2 = cf2.CreateChannelWithIssuedToken(samlToken);
            response = proxy2.Ping();

配置应该是这个样子:

Config should look something like this:

<customBinding>
        <binding name="SamlOverMutualSsl">
          <security defaultAlgorithmSuite="Default" authenticationMode="IssuedTokenOverTransport"
              requireDerivedKeys="true" securityHeaderLayout="Strict" includeTimestamp="false"
              keyEntropyMode="CombinedEntropy" messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10">
            <issuedTokenParameters keyType="BearerKey" tokenType="">
              <additionalRequestParameters>
                <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
                  <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
                </trust:SecondaryParameters>
              </additionalRequestParameters>
            </issuedTokenParameters>
            <localClientSettings cacheCookies="true" detectReplays="false"
                replayCacheSize="900000" maxClockSkew="00:05:00" maxCookieCachingTime="Infinite"
                replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00"
                sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true"
                timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
            <localServiceSettings detectReplays="false" issuedCookieLifetime="10:00:00"
                maxStatefulNegotiations="128" replayCacheSize="900000" maxClockSkew="00:05:00"
                negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00"
                sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00"
                reconnectTransportOnFailure="true" maxPendingSessions="128"
                maxCachedCookies="1000" timestampValidityDuration="00:05:00" />
            <secureConversationBootstrap />
          </security>
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
              messageVersion="Soap11" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </textMessageEncoding>
          <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
              maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
              bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
              keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
              realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
              useDefaultWebProxy="true" requireClientCertificate="true" />
        </binding>
      </customBinding>

端点:

<endpoint address="https://localhost/Ping/saml"
          binding="customBinding" bindingConfiguration="SamlOverMutualSsl"
          contract="SharedContracts.IPingService" name="WcfSamlOverMutualSsl" />

请参考添加到从WIF的Microsoft.IdentityModel。

Please add the reference to the Microsoft.IdentityModel from WIF.

希望这有助于。

rauts