2011-06-26 26 views
1

我有一个WCF 3.5服务,我需要使用jQuery调用它作为跨域调用,当我调用服务时我有返回正确的响应,但jQuery抛出异常parsererror状态 这是我的代码用于调用WCF服务使用AJAX调用WCF端点的问题jQuery

<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的调用错误函数,并抛出这个错误

jQuery161074459453323911_1309093997517 不叫

,这是我的WCF服务

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) 
     { 
      ...... 
     } 



} 

这是标记

<%@ ServiceHost Language="C#" Debug="true" Service="XXXX.SPServices.GlossaryService" CodeBehind="GlossaryService.svc.cs" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %> 

您的帮助表示赞赏

回答

1

WCF 3.5不支持跨域调用/ JSONP出框。您必须升级到WCF 4或检查this sample