I am get the above response when calling a WCF service via ajax json. My calling code is:
This is a pretty old question, but I'd like to add some information upon @carlosfigueira answer.
1. Specifying Factory
in .svc
vs. specifing a
in web.config
The alternative to specifying a Factory
in the .svc
file is specifying a
in the web.config
file. This is explained in many other answers (e.g. this one), so I won't repeat them, but it worth copying here yet another @carlosfigueira answer:
If you don't specify any factory in the .svc file, all the endpoints will come from the web.config file - WCF will try to find a
element whose
name
attribute matches the fully-qualified name of the service class. If it doesn't find one, then it will add a default endpoint (usingbasicHttpBinding
, unless you changed the default mapping).
And to be clear: the fully-qualified name should include the namespace. So if one has the following, it would be MyWebServices.ExampleWebService
:
namespace MyWebServices
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class ExampleWebService
{
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
public string DoWork(DoWorkRequest request)
{
return "success!";
}
}
}
2. Getting "Cannot process the message..." when called on localhost
I came to this question when trying to run an ajax call on localhost from Visual Studio, and got the error message which is the title of this question, so I'd like to list the required steps to solve it:
Factory
in the .svc
, or specify what's needed in the web.config
..html
file, and select "View in Browser". Your default browser would open, and if it's Chrome, the url would be, e.g, localhost:51667/test.html
(which is actually http://localhost:51667/test.html
).