我如何在 WSFederationHttpBinding 中支持流式传输? [英] How do I support streaming in WSFederationHttpBinding?

查看:33
本文介绍了我如何在 WSFederationHttpBinding 中支持流式传输?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a wcf service which is used to upload and download large files to server. I'm using MTOM message encoding and I want to use streamed transfer mode. But we are using wsFederationHttpBinding. How do I support streaming in wsFederationHttpBinding?

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

My WCF Service web.config code is given below,

<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>

推荐答案

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

It's been a few years, so I don't know if this still helps, but I came across this post while trying to figure out the same issue, so it might help someone.

事实证明,这其实很简单……只要你跳得恰到好处.

As it turns out, it's actually pretty simple..once you get the dance just right.

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

Probably the easiest thing (and what I tried first) is to inherit from WS2007FederationHttpBinding. As it turns out, it has a GetTransport method that's virtual, so you can override it and return an instance of HttpsTransport with TransferMode set to Streamed:

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

然而,这样做揭示了其他一些东西:因为我的绑定不再是一个公认的绑定类型,svcutil 不再把它当作一个 WS2007FederationHttpBinding,而是作为一个自定义绑定,这会导致生成客户端配置作为绑定元素的堆栈,而不是使用联邦绑定提供的快捷方式:

However, doing this revealed something else: since my binding was no longer a recognized binding type, svcutil didn't treat it like a WS2007FederationHttpBinding anymore, but rather as a custom binding, which lead to the client-side configuration being generated as a stack of binding elements rather than using the shortcuts provided by the federation binding:

    <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>

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

..which shows what the underlying binding elements actually are, which lets you tweak them all you like. And, as it turns out, they're really not that different from the actual binding since the only really special part is the security element, and it doesn't change much.

希望有所帮助.

这篇关于我如何在 WSFederationHttpBinding 中支持流式传输?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆