如何在Dot Net Core 2.1中创建SecurityBindingElement

时间:2018-06-25 19:01:35

标签: c# .net wcf asp.net-core asp.net-core-2.0

我正在尝试在点网核心网络api项目中使用wcf soap服务。因为dot net core不支持通过web.config文件进行配置。所有wcf配置我只需要在代码中完成,但在以下config中我无法在点网核心2.1中找到等效的代码

<customBinding>
   <binding name="SecureBinding">
  <security includeTimestamp="false"  
   authenticationMode="UserNameOverTransport" />
   <textMessageEncoding messageVersion="Soap11">
     <readerQuotas maxDepth="128" maxStringContentLength="2147483647" 
   maxArrayLength="2147483646" maxBytesPerRead="4096" 
   maxNameTableCharCount="16384000" />
   </textMessageEncoding>
  <httpsTransport  maxBufferPoolSize="524288" maxBufferSize="2147483647" 
   maxReceivedMessageSize="2147483647" requireClientCertificate="true"/>
</binding>

到目前为止,

在点网核心中编写的等效代码是

 var messegeElement = new TextMessageEncodingBindingElement
        {
            MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11),
            ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas
            {
                MaxDepth = 128,
                MaxStringContentLength = int.MaxValue,
                MaxArrayLength = int.MaxValue,
                MaxBytesPerRead = 4096,
                MaxNameTableCharCount = 16384000,

            }
        };

        HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement
        {
            MaxBufferSize = int.MaxValue,
            MaxReceivedMessageSize = int.MaxValue,
            RequireClientCertificate = true,
            AuthenticationScheme = AuthenticationSchemes.Ntlm,
            TransferMode = TransferMode.Buffered
        };

        CustomBinding customBinding = new CustomBinding(messegeElement, httpsTransport);

如何编写像这样的安全元素

 SecurityBindingElement sbe = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
 sbe.IncludeTimestamp = false;

我进行了搜索,但发现SecurityBindingElement在点网核心中尚不可用。对此是否有解决方法?

0 个答案:

没有答案