.Net核心上的WsHttpBinding

.Net核心上的WsHttpBinding,.net,wcf,.net-core,soap,wshttpbinding,.net,Wcf,.net Core,Soap,Wshttpbinding,我正在将.net4.x项目迁移到.netcore3.1。该项目严重依赖于SOAPweb服务。由于.Net Core不支持基于配置的WCF服务消费,因此我按代码调用该服务。当前项目使用ws2007HttpBinding绑定 我的问题是,ws2007HttpBinding在.netcore中没有正式存在。除了HttpBinding、HttpsBinding和CustomBinding之外,我没有其他选择。我用不同的配置尝试了所有这些方法,但每次都会遇到错误。有时它抱怨https方案(我使用的服务是h

我正在将
.net4.x
项目迁移到
.netcore3.1
。该项目严重依赖于
SOAP
web服务。由于
.Net Core
不支持基于配置的WCF服务消费,因此我按代码调用该服务。当前项目使用
ws2007HttpBinding
绑定

我的问题是,
ws2007HttpBinding
.netcore
中没有正式存在。除了
HttpBinding
HttpsBinding
CustomBinding
之外,我没有其他选择。我用不同的配置尝试了所有这些方法,但每次都会遇到错误。有时它抱怨
https
方案(我使用的服务是
https
),有时它说它期望
text/xml
,但没有看到它,这可能是由于双方使用的SOAP协议不同,有时我只是得到超时错误

在上一次尝试中,我安装了和更高版本的4.8.0-preview3.20412.3。后者具有和的隐含性。但是,两者都不起作用。这一次我犯了一个错误:

System.NotSupportedException:不支持指定的方法

我们高度赞赏任何解决方案或建议

这里是堆栈跟踪和部分代码:

System.AggregateException: One or more errors occurred. (Specified method is not supported.)
 ---> System.NotSupportedException: Specified method is not supported.
   at System.ServiceModel.MessageSecurityOverHttp.CreateSecurityBindingElement(Boolean isSecureTransportMode, Boolean isReliableSession, MessageSecurityVersion version)
   at System.ServiceModel.WSHttpSecurity.CreateMessageSecurity(Boolean isReliableSessionEnabled, MessageSecurityVersion version)
   at System.ServiceModel.WSHttpBinding.CreateMessageSecurity()
   at System.ServiceModel.WSHttpBindingBase.CreateBindingElements()
   at System.ServiceModel.WSHttpBinding.CreateBindingElements()
   at System.ServiceModel.Channels.Binding.EnsureInvariants(String contractName)
   at System.ServiceModel.Description.ServiceEndpoint.EnsureInvariants()
   at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
   at System.ServiceModel.ChannelFactory.CreateFactory()
   at System.ServiceModel.ChannelFactory.OnOpening()
   at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan timeout)
   at System.Runtime.TaskHelpers.WaitForCompletion(Task task)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at System.ServiceModel.ChannelFactory.EnsureOpened()
   at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
   at System.ServiceModel.ChannelFactory`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannel()
   at System.ServiceModel.ClientBase`1.CreateChannelInternal()
   at System.ServiceModel.ClientBase`1.get_Channel()
   at client.Inquiry_DataAsync(String NationalCode) in C:\Users\Reference.cs:line 5577
   at class1.<>c__DisplayClass13_0.<Inquiry_Data>b__0() in C:\Users\Code.cs:line 349
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification

Core不支持Wshttpbinding,wcf仅支持BasicHttpBinding、CustomBinding、NetHttpBinding、NetTcpBinding:

因此,目前有两种解决方案:

修改服务器的绑定,不要使用Wshttpbinding。

客户端继续使用.net framework。

有关core中WCF功能的更多信息,请参阅以下链接:


核心不支持Wshttpbinding,wcf仅支持BasicHttpBinding、CustomBinding、NetHttpBinding、NetCpBinding:

因此,目前有两种解决方案:

修改服务器的绑定,不要使用Wshttpbinding。

客户端继续使用.net framework。

有关core中WCF功能的更多信息,请参阅以下链接:


我无法修改服务器绑定,我们无法控制它。而且,
System.ServiceModel.Http
WsHttpBinding
的支持有限。不幸的是,这种支持在我的情况下是不够的。在这种情况下,客户端只能使用.net framework。我不能修改服务器绑定,我们无法控制它。而且,
System.ServiceModel.Http
WsHttpBinding
的支持有限。不幸的是,这种支持在我的情况下是不够的。在这种情况下,客户端只能使用.net framework。
        PermissiveCertificatePolicy.Enact("*");

        var binding = new WSHttpBinding();

        binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

        ServiceClient client = new ServiceClient(
            binding, new EndpointAddress("https://example.com/service.svc"));
        client.ClientCredentials.UserName.UserName = username;
        client.ClientCredentials.UserName.Password = password;
        client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication
        {
            CertificateValidationMode = X509CertificateValidationMode.None,
            RevocationMode = X509RevocationMode.NoCheck
        };

        _result = Task.Run(() => client.InquiryDataAsync("ABC")).Result;