Клиент Asp.Net Core 2.0 WCF CustomBinding PlatformNotSupportedException: BuildChannelFactoryCore не поддерживается - PullRequest
0 голосов
/ 12 февраля 2019

Мне нужно иметь возможность отправлять авторизацию в моем клиенте с помощью пользовательских привязок в Asp.Net Core 2.0.Он работает в Asp.net 4.6.1 и не работает в Core 2.2.Я пытаюсь подключиться к общедоступной веб-службе Workday нашего арендатора.Поскольку я смог выполнить эту работу в Asp.Net 4.6.1, я завершил там свою разработку, но хотел бы выяснить это для возможного будущего развития.

Я создал пользовательские привязки, которые я использовал в коде,см. ниже, однако, я всегда получаю эту ошибку: Полное сообщение:

System.PlatformNotSupportedException: TransportSecurityBindingElement.BuildChannelFactoryCore не поддерживается.

Моя реализация в Asp.Net Core 2.0 MVC:

     public async Task<bool> ImportTimeEntryBlockAsync(TimeEntry item)
       {
           bool isValid = true;
           //Create the update object to update the webservice           

           //setup Header
           Workday_Common_HeaderType header = new Workday_Common_HeaderType
           {
               Include_Reference_Descriptors_In_Response = true
           };

           //setup reported time block data from item
           Reported_Time_Block_DataType timeBlockData = new Reported_Time_Block_DataType();

           PopulateTimeBlock(item, ref timeBlockData);
           Reported_Time_Block_DataType[] timeBlocks = new Reported_Time_Block_DataType[1];
           timeBlocks[0] = timeBlockData;

           //setup import reported time block request
           Import_Reported_Time_Blocks_RequestType request = new Import_Reported_Time_Blocks_RequestType
           {
               version = "v29.0",
               Reported_Time_Block_Data = timeBlocks
           };
           Import_Reported_Time_BlocksInput timeBlock = new Import_Reported_Time_BlocksInput(header, request);

           //create client object
           Time_TrackingPortClient timeTracking = new Time_TrackingPortClient();
           timeTracking.ClientCredentials.UserName.UserName = IntegrationUser + @"@" + IntegrationDomain;
           timeTracking.ClientCredentials.UserName.Password = IntegrationPassword;

           SetupCustomBinding(timeTracking);

           //Set endpoint address
           Uri uri = new Uri(WorkdayHost + @"/Time_Tracking/v29.0");
           EndpointAddress endpoint = new EndpointAddress(uri);
           timeTracking.Endpoint.Address = endpoint;

           await timeTracking.OpenAsync();
           var result = await timeTracking.Import_Reported_Time_BlocksAsync(timeBlock);


           if (result == null)
               isValid = false;
           return isValid;
       }

       private static void SetupCustomBinding(Time_TrackingPortClient timeTracking)
       {
           // Create a custom binding that contains two binding elements; Security, Encoding and Transport

           //Security
           TransportSecurityBindingElement transportSecurity = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
           transportSecurity.IncludeTimestamp = true;

           XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas
           {
               MaxArrayLength = int.MaxValue,
               MaxBytesPerRead = int.MaxValue,
               MaxDepth = int.MaxValue,
               MaxNameTableCharCount = int.MaxValue,
               MaxStringContentLength = int.MaxValue
           };
           //encoding
           TextMessageEncodingBindingElement textEncoding = new TextMessageEncodingBindingElement
           {
               MessageVersion = MessageVersion.Soap11,
               ReaderQuotas = readerQuotas
           };

           // transport       
           HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement
           {
               AuthenticationScheme = AuthenticationSchemes.Basic,
               MaxBufferSize = int.MaxValue,
               MaxReceivedMessageSize = int.MaxValue,
               TransferMode = TransferMode.Buffered
           };

           SynchronizedCollection<BindingElement> coll = new SynchronizedCollection<BindingElement>
           {
               transportSecurity,
               textEncoding,
               httpsTransport
           };

           //Set Custom Binding
           CustomBinding binding = new CustomBinding(coll);
           timeTracking.Endpoint.Binding = binding;
       }

Ожидается, что он даст мне ответ, так как я смог заставить его работать в Asp.Net в настройке web.config:

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="IntegrationsBinding">
          <security mode="Transport"/>
        </binding>
        <binding name="IntegrationsBinding1"/>
      </basicHttpBinding>
      <customBinding>
        <binding name="WDWebServiceCustomBinding">
          <security authenticationMode="UserNameOverTransport" includeTimestamp="false">
            <secureConversationBootstrap/>
          </security>
          <textMessageEncoding messageVersion="Soap11">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          </textMessageEncoding>
          <httpsTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" realm=""/>
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://[webserver]/Time_Tracking/v31.0" binding="customBinding" bindingConfiguration="WDWebServiceCustomBinding" contract="TimeTracking.Time_TrackingPort" name="Time_Tracking"/>
      <endpoint address="https://[webserver]/Integrations/v31.0" binding="customBinding" bindingConfiguration="WDWebServiceCustomBinding" contract="Integration.IntegrationsPort" name="Integrations"/>
      <endpoint address="https://[webserver]/Absence_Management/v31.0" binding="customBinding" bindingConfiguration="WDWebServiceCustomBinding" contract="Absence.Absence_ManagementPort" name="Absence_Management"/>
    </client>
  </system.serviceModel>

Не думаю, что я реализовалэто неправильно, но нужно знать, если я что-то пропустил или BuildChannelFactoryCore все еще не поддерживается, то когда это будет?

Справочные блоги, где это упоминается:

https://github.com/dotnet/wcf/issues/13

https://github.com/dotnet/wcf/issues/1257

Спасибо,

Пол

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...