I’ve hosted WCFCore in .net 6 Console App. Code is below:
[ServiceContract]
public interface IServiceAPI
{
[OperationContract(IsOneWay = true)]
void DoWork();
}
public class ServiceAPI : IServiceAPI
{
IServiceAPICallBack Callback
{
get
{
return OperationContext.Current.GetCallbackChannel<IServiceAPICallBack>();
}
}
public void DoWork()
{
Callback.Result(2);
}
}
Program.cs
using CoreWCF;
using CoreWCF.Channels;
using CoreWCF.Configuration;
using CoreWCF.Description;
using System.Web.Services.Description;
using TestApp;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel((context, options) =>
{
options.AllowSynchronousIO = true;
});
// Add WSDL support
builder.Services.AddServiceModelServices().AddServiceModelMetadata();
builder.Services.AddSingleton<IServiceBehavior, UseRequestHeadersForMetadataAddressBehavior>();
var app = builder.Build();
var myWSHttpBinding = new WSHttpBinding(SecurityMode.Transport);
myWSHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
app.UseServiceModel(builder =>
{
builder.AddService<ServiceAPI>();
builder.AddServiceEndpoint<ServiceAPI, IServiceAPI>(new BasicHttpBinding(), "/ServiceAPI/basichttp");
builder.AddServiceEndpoint<ServiceAPI, IServiceAPI>(myWSHttpBinding, "/cowork");
});
var serviceMetadataBehavior = app.Services.GetRequiredService<ServiceMetadataBehavior>();
serviceMetadataBehavior.HttpGetEnabled = true;
app.Run();
When add Service reference from Client App I’m getting this error:
info: CoreWCF.Channels.ServiceModelHttpMiddleware[0]
Mapping CoreWCF branch app for path /ServiceAPI/basichttp
info: CoreWCF.Channels.ServiceModelHttpMiddleware[0]
Mapping CoreWCF branch app for path /coedit
info: CoreWCF.Channels.MetadataMiddleware[0]
Configuring metadata to /ServiceAPI/basichttp
info: CoreWCF.Channels.MetadataMiddleware[0]
Configuring metadata to /coedit
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:PerforceCoeditPOcUWPToOtherCommunicationTestApp
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
CoreWCF.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
at CoreWCF.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at CoreWCF.Channels.HttpInput.ValidateContentType()
at CoreWCF.Channels.HttpInput.ParseIncomingMessageAsync()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
CoreWCF.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
at CoreWCF.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at CoreWCF.Channels.HttpInput.ValidateContentType()
at CoreWCF.Channels.HttpInput.ParseIncomingMessageAsync()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
CoreWCF.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
at CoreWCF.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at CoreWCF.Channels.HttpInput.ValidateContentType()
at CoreWCF.Channels.HttpInput.ParseIncomingMessageAsync()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
CoreWCF.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
at CoreWCF.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at CoreWCF.Channels.HttpInput.ValidateContentType()
at CoreWCF.Channels.HttpInput.ParseIncomingMessageAsync()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
CoreWCF.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8. The client and service bindings may be mismatched.
at CoreWCF.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription)
at CoreWCF.Channels.HttpInput.ValidateContentType()
at CoreWCF.Channels.HttpInput.ParseIncomingMessageAsync()
at CoreWCF.Channels.AspNetCoreReplyChannel.HandleRequest(HttpContext context)
at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context)
at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context)
at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I’ve tried add service reference from visual studio.
appsettings.json
{
"Urls": "http://localhost:5000;https://localhost:5001",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
2
Answers
According to the error message, the server and client bindings are different. First you need to check the bindings on both sides.
Then you can try using custom bindings. You can take a look at this Case.
Use the full path from "http://localhost:5000;https://localhost:5001/yourXamlConfigPathFromWeb"
As SOAP expecting a xaml but localhost url returning html, this issue happened. Please use fully qualified xaml path to add service reference.