WCF 命令式绑定

发布于 2024-10-16 14:40:32 字数 4000 浏览 5 评论 0原文

如何将以下声明式(通过配置文件)绑定转换为命令式绑定(在应用程序内部硬编码)?

<system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="CustomBinding_IAEService">
                    <security defaultAlgorithmSuite="Basic256Sha256Rsa15" authenticationMode="MutualCertificateDuplex"
                        requireDerivedKeys="false" securityHeaderLayout="Lax" includeTimestamp="true" allowSerializedSigningTokenOnReply="true"
                        keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncrypt"
                        messageSecurityVersion="Default" requireSignatureConfirmation="false">
                        <localClientSettings cacheCookies="true" detectReplays="true"
                            replayCacheSize="900000" maxClockSkew="00:05:00"
                            replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00"
                            sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true"
                            timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
                        <localServiceSettings detectReplays="true" 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="Soap12" 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="false" />
                </binding>
            </customBinding>
        </bindings>

谢谢

编辑:

在阿迪斯拉夫重播后我尝试过:

    // configure security properties
    AsymmetricSecurityBindingElement security = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.Default);
    security.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15;
    security.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
    security.AllowSerializedSigningTokenOnReply = true;
    security.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
    security.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
    security.RequireSignatureConfirmation = false;

    // configure encoding properties
    TextMessageEncodingBindingElement encoding = new TextMessageEncodingBindingElement();

    // configure transport properties
    HttpsTransportBindingElement transport = new HttpsTransportBindingElement();

    CustomBinding customBinding = new CustomBinding(security, encoding, transport);

但是这个代码不起作用。我想念什么?

谢谢

How to translate the following declarative (via configuration file) binding, to imperative binding (hardcoded inside application)?

<system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="CustomBinding_IAEService">
                    <security defaultAlgorithmSuite="Basic256Sha256Rsa15" authenticationMode="MutualCertificateDuplex"
                        requireDerivedKeys="false" securityHeaderLayout="Lax" includeTimestamp="true" allowSerializedSigningTokenOnReply="true"
                        keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncrypt"
                        messageSecurityVersion="Default" requireSignatureConfirmation="false">
                        <localClientSettings cacheCookies="true" detectReplays="true"
                            replayCacheSize="900000" maxClockSkew="00:05:00"
                            replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00"
                            sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true"
                            timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" />
                        <localServiceSettings detectReplays="true" 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="Soap12" 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="false" />
                </binding>
            </customBinding>
        </bindings>

Thanks

EDIT:

After Adislav's replay I tryed with:

    // configure security properties
    AsymmetricSecurityBindingElement security = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.Default);
    security.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15;
    security.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
    security.AllowSerializedSigningTokenOnReply = true;
    security.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
    security.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
    security.RequireSignatureConfirmation = false;

    // configure encoding properties
    TextMessageEncodingBindingElement encoding = new TextMessageEncodingBindingElement();

    // configure transport properties
    HttpsTransportBindingElement transport = new HttpsTransportBindingElement();

    CustomBinding customBinding = new CustomBinding(security, encoding, transport);

But this code doesn't work. What do I miss?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-10-23 14:40:32

您必须使用 System.ServiceModel.Channels.CustomBinding 类和相关绑定元素(来自同一命名空间):

  var security = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.Default);
  // configure security properties
  var encoding = new TextMessageEncodingBindingElement();
  // configure encoding properties
  var transport = new HttpsTransportBindingElement();
  // configure transport properties
  var customBinding = new CustomBinding(security, encoding, transport);

You have to use System.ServiceModel.Channels.CustomBinding class and related binding elements (from the same namespace):

  var security = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.Default);
  // configure security properties
  var encoding = new TextMessageEncodingBindingElement();
  // configure encoding properties
  var transport = new HttpsTransportBindingElement();
  // configure transport properties
  var customBinding = new CustomBinding(security, encoding, transport);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文