将传输安全性添加到customBinding

时间:2012-06-20 23:47:20

标签: c# wcf

我有一个customizeBinding,我在CreateBindingElemens方法中添加了各种绑定。如果我有HttpTransportBindingElement,一切都很好,但作为下一步我想添加传输安全性(ssl),所以我修改了这样的代码

        BindingElementCollection collection = new BindingElementCollection();
        collection.Add(httpPollingElement);
        if (session == SessionType.HttpSession)
        {
            collection.Add(httpSessionElement);
        }
        else
        {
            collection.Add(reliableSessionElement);
        }

        collection.Add(encodingElement);


        var securityBindingElement = new TransportSecurityBindingElement();
        collection.Add(securityBindingElement);
        collection.Add(httpTransportElement);
        return collection;

但是我收到错误说绑定'System.ServiceModel.Channels.CustomBinding'的安全功能与生成的运行时对象的安全功能不匹配。这很可能意味着绑定包含StreamSecurityBindingElement,但缺少支持Stream Security的TransportBindingElement(例如TCP或命名管道)。删除未使用的StreamSecurityBindingElement或使用支持此元素的传输。

我可以确认我的配置中没有StramSecurityBindingElement。我应该添加哪些安全绑定才能使其工作?

1 个答案:

答案 0 :(得分:1)

要使用ssl,只需添加:

new HttpsTransportBindingElement()

而不是http元素。 当仅使用传输安全性时,无需添加安全元素。

相关问题