I have a WCF service that needs to be called via SOAP (working) and via JSON (not working).
My C# code:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(ResponseFormat=WebMessageFormat.Json)]
string Foo();
}
public class Service1 : IService1
{
public string Foo()
{
return "woohooo";
}
}
And here's my config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Service1">
<endpoint address="soap" binding="basicHttpBinding" contract="DummyService.IService1"/>
<endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="DummyService.IService1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript/>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And here's my Javascript:
$.getJSON("/Service1.svc/Foo")
.success(function (result) {
alert("success! " + result);
})
.fail(function (result) {
console.log("failed!");
console.log(result);
});
The response I get is "400 Bad Request". What am I doing wrong? I've followed the advice in REST / SOAP endpoints for a WCF service, but it still-a-no-worksies. :-) Help!