Content Type text/xml charset=utf-8 was not supported by service

I was trying to consume a WCF service from SharePoint web part. Basically I got this error “Content Type text/xml charset=utf-8 was not supported by service. The client and server bindings may be mismatched”. After a bit of analysis, I’ve realized that the three was mismatch in the Binding type specified in the service and client configuration.  At the service-level, I had configured WSHttpBinding and at the client it was configured as BasicHttpBinding. I’ve fixed this issue by making sure that the bindings match at both the client and server.

 

WCF error: could not find default end point element that references contract

I was trying to consume an IIS hosted WCF service, got this error “could not find default end point element that references contract in the ServiceModel client configuration. This might be because no endpoint element matching this contract could be found in the client element”.

I fixed it by performing the following steps:-

1. Included the following namespace in the WCF client component

using System.ServiceModel;
using System.Runtime.Serialization;

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

If the WCF client project is of type .NET 3.5 or higher, it will have references to System.ServiceModel.dll and System.Runtime.Serialization.dll. It will not have references to those namespaces in the code, this needs to be added.

2. Changed the name of the client configuration file from ‘output.config’ to ‘app.config’. When I generated client proxy using svcutil.exe, I set the default name of output.config and this needs to be changed to ‘app.config’.If your client is a web application, you can copy the contents inside System.ServiceModel to the web.config

After doing the above 2 steps, my WCF client worked like a charm.

 Subscribe to my blog

WCF error: The service cannot be activated because it does not support ASP.NET compatibility

I got the following error when I was trying to host my WCF service in IIS 7.5 using WsHttpBinding

The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’.

Solution:

One of the  solution is to turn-off ASPNet compatibility in service configuration file

<serviceHostingEnvironment aspNetCompatibilityEnabled="false"/>. It worked for me.

WCF error: SOAP security negotiation failed for target

I got this error when I tried to host the WCF service in the IIS 7.5 using WSHttpBinding.

Exception
[System.ServiceModel.Security.SecurityNegotiationException] {"SOAP security negotiation with ‘http://localhost/Migraton/MigrationService.svc&#8217; for target ‘http://localhost/OrderService/OrderService.svc&#8217; failed. See inner exception for more details."}

Inner Exception
[System.ComponentModel.Win32Exception] {"The Security Support Provider Interface (SSPI) negotiation failed."}

Solution

The solution was to change the following userPrincipalName in the <userPrincipalName value="MACHINENAMEASPNET" /> to <servicePrincipalName value="host/localhost" /> . This did the trick and solved the issue.