【问题标题】:How do I support streaming in WSFederationHttpBinding?如何在 WSFederationHttpBinding 中支持流式传输?
【发布时间】:2015-09-29 22:32:30
【问题描述】:

我有一个 wcf 服务,用于将大文件上传和下载到服务器。我正在使用 MTOM 消息编码,并且我想使用流传输模式。但是我们使用的是 wsFederationHttpBinding。如何在 wsFederationHttpBinding 中支持流式传输?

我的 WCF 服务 web.config 代码如下,

<wsFederationHttpBinding>
 <binding  name="UploadserviceFederation"
                      messageEncoding="Mtom"
                  maxBufferPoolSize="2147483647"
                  maxReceivedMessageSize="2147483647" >
          <readerQuotas maxStringContentLength="2147483647"
                      maxDepth="2147483647"
                      maxBytesPerRead="2147483647"
                      maxArrayLength="2147483647"/>

          <security mode="TransportWithMessageCredential">
            <!-- Ping token type MUST be SAML 1.1, do not change -->
            <message 
              issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" negotiateServiceCredential="false">
              <!-- TODO: You must put the proper issuer URN of the Ping STS; normally this would be the Ping base URL -->
              <issuer address="https://my-issuer.com" binding="customBinding" bindingConfiguration="FileUploadSTSBinding" />
            </message>
          </security>
        </binding>

      </wsFederationHttpBinding>


<customBinding>
        <binding name="FileUploadSTSBinding">
          <security authenticationMode="UserNameOverTransport" requireDerivedKeys="false"
              keyEntropyMode="ServerEntropy" requireSecurityContextCancellation="false"
              requireSignatureConfirmation="false">
          </security>
          <httpsTransport maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" />
        </binding>
</customBinding>

【问题讨论】:

    标签: wcf streaming ws-federation


    【解决方案1】:

    已经有几年了,所以我不知道这是否仍然有帮助,但我在试图找出同样的问题时遇到了这篇文章,所以它可能会对某人有所帮助。

    事实证明,它实际上非常简单......只要你的舞蹈恰到好处。

    可能最简单的事情(也是我首先尝试的)是从 WS2007FederationHttpBinding 继承。事实证明,它有一个虚拟的 GetTransport 方法,因此您可以覆盖它并返回一个 HttpsTransport 实例,并将 TransferMode 设置为 Streamed:

    public class FileUploadSTSBinding : WS2007FederationHttpBinding
    {
        protected override TransportBindingElement GetTransport()
        {
            return new HttpsTransportBindingElement()
            {
                TransferMode = TransferMode.Streamed
            };
        }
    }
    

    然而,这样做揭示了另外一些东西:由于我的绑定不再是一个可识别的绑定类型,svcutil 不再将其视为 WS2007FederationHttpBinding,而是将其视为自定义绑定,这会导致生成客户端配置作为绑定元素的堆栈,而不是使用联合绑定提供的快捷方式:

        <customBinding>
                    <binding name="CustomBinding_ISdk">
                        <security defaultAlgorithmSuite="Default" authenticationMode="IssuedTokenOverTransport"
                            requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10">
                            <issuedTokenParameters keyType="BearerKey">
                                <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 detectReplays="false" />
                            <localServiceSettings detectReplays="false" />
                        </security>
                        <textMessageEncoding />
                        <httpsTransport />
                    </binding>
    

    ..它显示了底层绑定元素实际上是什么,它可以让你随意调整它们。而且,事实证明,它们与实际绑定并没有太大区别,因为唯一真正特殊的部分是安全元素,并且变化不大。

    希望对您有所帮助。

    【讨论】:

    • 我不知道我是否遗漏了什么,但是我们如何将其余配置应用于 FileUploadSTSBinding?我知道这是旧的.. 但我在同一个地方!
    • 我不确定我是否理解您的问题。如果您使用第一个框中的方法,那么您通常可以在配置文件中访问的所有设置都应该作为属性提供。如果您使用第二个框中的方法,您应该可以访问您通常会访问的所有内容,然后是一些。属性名称会有所不同(因为您直接处理绑定元素,而不是花哨的、友好的固定绑定类型),但所有内容和更多内容都应该在那里,并且您应该在 Visual Studio 中获得智能感知。您是否特别在寻找什么?
    • 好的.. 很晚了,我搞糊涂了!我现在看到所有属性都可用于 WS2007FederationHttpBinding 的子类。我向它添加了所有代码并将其插入到 ServiceHostFactory 中,它看起来很正确。但是,当我从另一个项目或 SVCUtil 引用此服务时,我看到它确实(令人讨厌地)正确地将其识别为“ws2007FederationHttpBinding”而不是自定义绑定。这让我回到了起点,因为我无法弄清楚如何指定 Stream 选项(在这种情况下,Co 策略会查找配置)。
    • 好的。现在我明白了 - 它要么全部以编程方式,要么全部配置。我想我可以采用上面的方法#1(子类),然后从 WS2007FederationHttpBinding 的 xml 应用配置。因为我们需要使用 xml 配置,所以我将完整绑定重新构建为自定义绑定。当您退后一秒并使用 RTFM 时才有意义 :)
    • 我可能很快就会自己走上这条路。想到一个问题:为什么默认情况下不启用?
    【解决方案2】:

    您必须在自定义绑定中启用流传输模式,因为只有 BasicHttpBindingNetTcpBindingNetNamedPipeBinding 绑定公开了 TransferMode 属性。示例见this 文章。

    【讨论】:

    • 那我就不能用wsFederationHttpBinding和流传输模式了吧?
    • 不,但是您可以创建一个自定义绑定来模拟 WsFederationHttpBinding 绑定所做的事情,但要小心。
    • 您有任何模拟 WsFederationHttpBinding 的自定义绑定示例吗?
    • 不幸的是我没有。 WsFederationHttpBinding 绑定与WsHttpBinding 绑定非常相似。究竟为什么需要使用WsFederationHttpBinding 绑定?
    • 我们使用基于令牌的身份验证,我们有一个集中的身份验证来验证不同的应用程序。
    猜你喜欢
    • 1970-01-01
    • 2010-11-30
    • 2014-02-15
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 2017-08-01
    • 2018-02-21
    相关资源
    最近更新 更多