i have a WCF 3.5 service where i need to call it using jQuery as cross domain call, when i call the service i have return correct response but jQuery throw an exception parsererror status
this is the code i use to call the WCF service
<script type="text/javascript">
$(document).ready(function () {
var wordlist = $("#main-container").text()
$.ajax({
type: "GET",
contentType: 'application/json; charset=utf-8',
url: 'http://192.168.1.210:8080/XXXX.SPServices/GlossaryService.svc/GetWordsWithDifenition',
dataType: 'jsonp',
data: { 'stringwords': wordlist },
success: function (data) {
PutLinkToDefinition(data);
},
error: function (jqXHR, textStatus, errorThrown) {
debugger;
}
});
});
</script>
jQuery calls the error function and throws this error
jQuery161074459453323911_1309093997517
was not called
and this is my WCF service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Microsoft.SharePoint.Client.Application;
using Microsoft.SharePoint.Client;
using System.Net;
using System.Configuration;
namespace XXXX.SPServices
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class GlossaryService
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
[WebGet]
public Dictionary<string,string> GetWordsWithDifenition(string stringwords)
{
......
}
}
this is the markup
<%@ ServiceHost Language="C#" Debug="true" Service="XXXX.SPServices.GlossaryService" CodeBehind="GlossaryService.svc.cs" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
your help is appreciated
WCF 3.5 doesn’t support cross domain calls / JSONP out of the box. You must either upgrade to WCF 4 or check this sample.