如何在WSFederationHttpBinding中支持流式传输?

时间:2012-04-05 18:27:40

标签: wcf streaming ws-federation

我有一个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>

2 个答案:

答案 0 :(得分:2)

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

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

可能最简单的事情(以及我先尝试过的)是继承自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>

..它显示了实际的基础绑定元素,它可以让你随心所欲地调整它们。事实证明,它们与实际绑定并没有什么不同,因为唯一真正特殊的部分是安全元素,它并没有太大变化。

希望有所帮助。

答案 1 :(得分:1)

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