I want my WCF service to return json.
I test it on ASP.NET Development Server and it works from WCF Test Client (method invokation is ok).
But testing from browser fails with error 400 bad request.
web.config
:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WebServiceExample"
behaviorConfiguration="MetadataBehaviour">
<endpoint
address=""
behaviorConfiguration="AjaxBehaviour"
binding="webHttpBinding"
contract="WebService.IWebServiceExample">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior name="MetadataBehaviour">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Contract:
[ServiceContract]
public interface IWebServiceExample
{
[OperationContract]
[WebGet(UriTemplate = "/check/{key}",
ResponseFormat = WebMessageFormat.Json)]
DataElement Check(string key);
}
[DataContract]
public class DataElement
{
[DataMember]
public string Key { get; set; }
[DataMember]
public DateTime DateSince { get; set; }
[DataMember]
public DateTime DateTill { get; set; }
}
SVC Markup:
<%@ ServiceHost Language="C#" Debug="true"
Service="WebService.WebServiceExample"
CodeBehind="WebServiceExample.svc.cs" %>
the URI I try is:
http://localhost:16679/WebServiceExample.svc/check/asd