C# .NET 8.0 WCF -Client kann den WCF -Dienst nicht aufrufen. Sagt Inhaltstypanwendung/Seife+XML; charset = utf-8; wurde
Posted: 11 Feb 2025, 05:14
Ich habe einen .NET 4.6 -WCF -Client, der perfekt funktioniert. Es wird immer wieder gesagt: < /p>
C# .NET 8.0 WCF -Client kann den WCF -Dienst nicht aufrufen. Inhaltstypanwendung/SOAP+XML; charset = utf-8; wurde nicht vom Dienst unterstützt. Die Kunden- und Service -Bindungen können nicht angemessen sein.
Ich habe jede Kombination aus möglichen Bindungen ausprobiert, aber ich bekomme immer noch die gleiche Ausnahme.
C# .NET 8.0 WCF -Client kann den WCF -Dienst nicht aufrufen. Inhaltstypanwendung/SOAP+XML; charset = utf-8; wurde nicht vom Dienst unterstützt. Die Kunden- und Service -Bindungen können nicht angemessen sein.
Ich habe jede Kombination aus möglichen Bindungen ausprobiert, aber ich bekomme immer noch die gleiche Ausnahme.
Code: Select all
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(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);
}
< /code>
Dieser hat auch nicht funktioniert < /p>
// 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(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);
}