gpt4 book ai didi

asp.net-core-2.0 - Asp.Net Core 2.0 WCF 客户端 CustomBinding PlatformNotSupportedException : BuildChannelFactoryCore is not supported

转载 作者:行者123 更新时间:2023-12-03 17:30:41 24 4
gpt4 key购买 nike

我需要能够使用 Asp.Net Core 2.0 中的自定义绑定(bind)在我的客户端中发送授权。它适用于 Asp.net 4.6.1,不适用于 Core 2.2。我正在尝试连接到租户中的 Workday 公共(public) Web 服务。因为我能够在 Asp.Net 4.6.1 中完成这项工作,所以我在那里完成了我的开发,但想弄清楚这一点以备将来可能的开发。

我创建了在代码中使用的自定义绑定(bind)。见下文,但是,我总是收到此错误:
完整留言:

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;
}

预计它会给我一个回应,因为我能够让它在 web.config 设置中的 Asp.Net 中工作:
  <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

谢谢,

保罗

最佳答案

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);

关于asp.net-core-2.0 - Asp.Net Core 2.0 WCF 客户端 CustomBinding PlatformNotSupportedException : BuildChannelFactoryCore is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54657228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com