How do I support streaming in WSFederationHttpBinding?

放肆的年华 提交于 2019-12-07 01:00:32

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.

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

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.

Hope that helps.

You will have to enable streamed transfer mode in a custom binding since only the BasicHttpBinding, NetTcpBinding and NetNamedPipeBinding bindings expose the TransferMode property. See this article for an example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!