将传输安全性添加到自定义绑定



我有一个自定义绑定,其中我在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;

但是我收到一个错误,指出绑定"系统.服务模型.通道.自定义绑定"的安全功能与生成的运行时对象的安全功能不匹配。这很可能意味着绑定包含 StreamSecurityBindingElement,但缺少支持 Stream Security(如 TCP 或命名管道)的 TransportBindingElement。删除未使用的 StreamSecurityBindingElement 或使用支持此元素的传输。

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

要使用 ssl 只需添加:

new HttpsTransportBindingElement()

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

最新更新