I am trying to catalog for my own education the multiple ways services are used in an asp.net application.
When using a standard (i.e. non-ajax) WCF service, if you use an endpoint behavior with "webHttp", a json result is not wrapped with "d". If you use an endpoint behavior with "enableWebScript", you get the expected "d" wrapper.
Is this a feature of .net 4.5 now, or why is it that you don't get the "d" wrapper with webHttp?
My understanding now is that it is the underlying MS-AJAX infrastructure that implements the "d" wrapper, and if you use WCF without the AJAX infrastructure (e.g. if setting up a RESTful service), you avoid this.
I don't have any real complex implementation - I am just trying to capture the nuances of the different ways of implementing services - but just in case, here is the code I used to discover this behavior with "d".
Here is the exposed method:
[ServiceContract]
public interface IServicesDemo_WCF
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
string ReturnWcfMessage();
}
Here is the config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebService.AJAX_WCFAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="WebService.WCFBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="WCFServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="WebService.ServicesDemo_AJAX_WCF">
<endpoint address="" behaviorConfiguration="WebService.AJAX_WCFAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebService.ServicesDemo_AJAX_WCF" />
</service>
<service name="WebService.ServicesDemo_WCF" behaviorConfiguration="WCFServiceBehavior">
<endpoint address="" behaviorConfiguration="WebService.WCFBehavior"
binding="webHttpBinding" contract="WebService.IServicesDemo_WCF" />
</service>
</services>
Here is the call from client:
$.ajax({
type: "Get",
data: data,
contentType: "application/json; charset=utf-8",
url: "ServicesDemo_WCF.svc/ReturnWcfMessage",
success: function (data) {
$('#wcf_content').html(data);
},
error: function (msg) {
alert(msg);
}
});