首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以编程方式创建此自定义绑定?

如何以编程方式创建此自定义绑定?
EN

Stack Overflow用户
提问于 2010-03-31 20:56:01
回答 3查看 22.8K关注 0票数 21

我们必须访问使用soap11的web服务...没问题,我只需将绑定设置为:

代码语言:javascript
复制
BasicHttpBinding wsBinding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);

不是的。没有骰子。所以我问服务的宿主为什么我们会有身份验证问题,他说我们的配置需要有这个自定义绑定:

代码语言:javascript
复制
<bindings>
    <customBinding>
        <binding name="lbinding">
            <security  authenticationMode="UserNameOverTransport" 
                messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11" 
                securityHeaderLayout="Strict" 
                includeTimestamp="false"
                requireDerivedKeys="true" 
                keyEntropyMode="ServerEntropy">
            </security>
            <textMessageEncoding messageVersion="Soap11" />
            <httpsTransport authenticationScheme ="Negotiate" requireClientCertificate ="false" realm =""/>
        </binding>
    </customBinding>
</bindings>

唯一的问题是我们以编程的方式创建绑定,而不是通过配置。因此,如果有人能为我指出正确的方向,将我的BasicHttpBinding更改为符合.config值的自定义绑定,我会给他们一大颗闪亮的金星。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-03-31 23:12:24

解决了!

以下是那些处于类似困境的人的获胜代码。

代码语言:javascript
复制
Uri epUri = new Uri(_serviceUri);
CustomBinding binding = new CustomBinding();
SecurityBindingElement sbe = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
sbe.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11;        
sbe.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
sbe.IncludeTimestamp = false;
sbe.SetKeyDerivation(true);
sbe.KeyEntropyMode = System.ServiceModel.Security.SecurityKeyEntropyMode.ServerEntropy;
binding.Elements.Add(sbe);
binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8));
binding.Elements.Add(new HttpsTransportBindingElement());
EndpointAddress endPoint = new EndpointAddress(epUri);
票数 37
EN

Stack Overflow用户

发布于 2012-08-10 09:24:13

@D. Forrest已经找到了解决方案,但要查看给定的WCF配置涉及哪些对象,一个简单的方法是在您正在使用的客户端代理上调用.Endpoint.Binding.CreateBindingElements()。您可以转储返回的列表中每个项目的对象树,并查看绑定是如何配置的。

票数 8
EN

Stack Overflow用户

发布于 2018-11-01 20:14:23

可以使用的 :

代码语言:javascript
复制
        Uri epUri = new Uri("http://localhost/TestWCFService/Service.svc");
        CustomBinding binding = new CustomBinding()
        {
            Name = "anyname",
            ReceiveTimeout = new TimeSpan(0, 0, 10, 0, 0),
            SendTimeout = new TimeSpan(0, 0, 10, 0, 0),
        };
        var element1 = new TextMessageEncodingBindingElement()
        {
            ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
            {
                MaxDepth = 2147483647,
                MaxStringContentLength = 2147483647,
                MaxArrayLength = 2147483647,
                MaxBytesPerRead = 2147483647,
                MaxNameTableCharCount = 2147483647
            }
        };
        var element2 = new HttpsTransportBindingElement()
        {
            ManualAddressing = false,
            MaxReceivedMessageSize = 2147483647,
            AllowCookies = false,
            AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous,
            BypassProxyOnLocal = false,
            MaxBufferSize = 2147483647,
            ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous,
            TransferMode = TransferMode.Buffered,
            UseDefaultWebProxy = true
        };
        var element3 = new TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8);

        binding.Elements.Add(element1);
        binding.Elements.Add(element2);
        binding.Elements.Add(element3);

        //binding.Elements.Add(new HttpsTransportBindingElement());

        EndpointAddress endPoint = new EndpointAddress(epUri);
        var client = new ServiceClient(binding, endPoint);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2553013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档