During the last 4 hours i’ve been looking at any post I could find regarding this question, so I might be a little blind by now 😉
I am trying to call a simple WCF service using jQuery. I’ve been using WebMethods for some time, and I am trying to migrate some. I am trying to test with the most simple webservice you can imagine:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ForumOperationService : IForumOperationService
{
public string Horse(string prefixText, int count)
{
return "hestWCF";
}
}
My jQuery call:
$(document).ready(function () {
var hest;
$.ajax({
type: "POST",
datatype: "application/json",
url: "Services/ForumOperationService.svc/Horse",
data: { prefixText: 'a', count: 10 },
success: function (data) {
hest = data;
}
});
});
My web.config is like this:
<system.webServer>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="ForumOperationService">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="IForumOperationService" />
</service>
</services>
.... (more stuff)
In Firebug I get the following error:
NetworkError: 500 Internal Server Error –
http://localhost:21599/Client/Services/ForumOperationService.svc/Horse
Any ideas?
UPDATE:
Just ran the WCF Test Client, and got this error:
The service class of type ForumOperationService both defines a
ServiceContract and inherits a ServiceContract from type
IForumOperationService. Contract inheritance can only be used among
interface types. ÿIf a class is marked with ServiceContractAttribute,
it must be the only type in the hierarchy with
ServiceContractAttribute. ÿConsider moving the
ServiceContractAttribute on type IForumOperationService to a separate
interface that type IForumOperationService implements.
Will follow up tomorrow.
Test the method using WCFTestClient(.exe) and confirm that method is working fine, you will get actual error if not.
If your method params easy enough, WCFTestClient is quick way to test out before start using it from application code.