admin管理员组文章数量:1301507
I have a .NET 4.6 WCF Client which works perfectly fine. When I convert WCF to .NET 8.0, it doesn't work. It keeps saying:
C# .NET 8.0 WCF client cannot call WCF service. Content Type application/soap+xml; charset=utf-8; was not supported by service. he client and service bindings may be mismatched.
This makes no sense because the service uses CustomBindings with SOAP 1.2 (HTTPS and Basic Authentication)
I have tried every possible bindings combination but I still keep getting the same exception.
Any ideas?
var binding = new CustomBinding();
binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12, Encoding.UTF8));
binding.Elements.Add(new HttpsTransportBindingElement());
var endpointAddress = new EndpointAddress(serviceUri);
var channelFactory = new ChannelFactory<IReceiveFileInfoService>(binding, endpointAddress);
channelFactory.Credentials.UserName.UserName = userName;
channelFactory.Credentials.UserName.Password = password;
IReceiveFileInfoService client = channelFactory.CreateChannel();
var model = GetSampleModel();
try
{
// Call the service
var response = await client.SubmitInfoAsync(model);
Console.WriteLine("Service response: " + response);
}
catch (Exception ex)
{
Console.WriteLine("Error calling service: " + ex.Message);
}
This one didn't work either
// Set a custom certificate validation callback
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
// Define the service endpoint address (HTTPS)
var endpointAddress = new EndpointAddress(serviceUri);
// Create a binding for HTTPS with Basic Authentication
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport; // Use HTTPS
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; // Basic Authentication
// Create the ChannelFactory
var channelFactory = new ChannelFactory<IFileInfoService>(binding, endpointAddress);
// Set the credentials (username and password)
channelFactory.Credentials.UserName.UserName = userName;
channelFactory.Credentials.UserName.Password = password;
// Create the channel (proxy)
IFileInfoService client = channelFactory.CreateChannel();
var model = GetSampleModel();
try {
// Call the service method
var result = await client.SubbmitInfoAsync(model);
Console.WriteLine("Service response: " + result);
}
catch (Exception ex)
{
Console.WriteLine("Error calling service: " + ex.Message);
}
本文标签:
版权声明:本文标题:asp.net core - C# .NET 8.0 WCF client cannot call WCF service. Says Content Type applicationsoap+xml; charset=utf-8; was not sup 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741678861a2392045.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论