2013-05-09 38 views
0

对于我最近的项目,我创建了一个Web服务,它将自定义类型的数组返回给jquery客户端代码。 WCF通过$.ajax命令调用,并位于同一个域中。WCF jquery parsererror未终止的字符串常量响应

当我在localhost上运行我的web应用程序(这是在本地机器上运行的IIS)时,一切正常。当我将它部署到我们的集成服务器时,突然ajax调用WCF结束时出现错误:“parsererror - 未终止的字符串常量”,状态为200.然而,返回的消息类似于"[{\"Text\":\"Test dodatnih naslov",这当然不是正确的json格式。

正确反应应该是:"[{"Text":"Test dodatnih naslovov","Value":"100"},{"Text":"Test dodatnih naslovov - ISO2","Value":"101"},{"Text":"UPDATE","Value":"102"}]"

我已经追踪WCF服务malfuncitons,但它似乎并没有被撞毁。我也试过并设置了超时给ajax调用,但无济于事。一些帮助将不胜感激。

我的IIS是IIS7,其中积分IIS6运行在Windows Server 2008上

JS文件

function InsuranceClientContact_ItemsRequesting(o, e) { 
    var $ = $telerik.$; 
    var urlSvc = ServiceBaseUrl + '/GetContacts' 
    $.ajax({ 
     type: "POST", 
     url: urlSvc, 
     data: '{"ixClient": ' + selectedItemId + '}', //selectedItemId is a positive number 
     dataType: "json", 
     contentType: "application/json; charset=utf-8", 
     success: function (data) { 
      // do something 
     }, 
     error: function (result) { 
      var msg = result.status + " - " + result.statusText; 
      setTimeout(function() { throw new Error(msg) }, 0); 
     } 
    }); 

WCF接口

namespace Sid.Skode.Web.Services.Populate { 
    [ServiceContract] 
    public interface IInsuranceClientContactService { 
     [OperationContract] 
     [WebInvoke(Method="POST", 
      BodyStyle=WebMessageBodyStyle.WrappedRequest, 
      ResponseFormat=WebMessageFormat.Json)] 
     Contact[] GetContacts(long ixClient); 
    } 

    [DataContract] 
    public class Contact { 
     [DataMember] 
     public string Text; 
     [DataMember] 
     public string Value; 
    } 

} 

WCF服务实现

namespace Sid.Skode.Web.Services.Populate { 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    public class InsuranceClientContactService : IInsuranceClientContactService { 

     public Contact[] GetContacts(long ixClient) { 
      return GetContactsFromDatabase(ixClient); 
     } 

     #region Private methods 

     private Contact[] GetContactsFromDatabase(long ixClient) { 
      DataTable dt = GetDataFromDataBaseById(ixClient); 
      return ConvertDataTableToContactArray(dt); 
     }   

     private DataTable GetDataFromDataBaseById(long ixClient) { 
      AutoCompleteBLL model = new AutoCompleteBLL(); 
      return model.SearchContactsByPartner(ixClient); 
     } 

     private Contact[] ConvertDataTableToContactArray(DataTable dt) { 
      Contact[] rgContact = new Contact[dt.Rows.Count]; 
      int cnContact = 0; 
      foreach (DataRow dr in dt.Rows) { 
       if (!dr.IsNull("NAZIV")) { 
        Contact contact = new Contact(); 
        contact.Text = dr["NAZIV"].ToString(); 
        contact.Value = dr["ID_DODATEN_KONTAKT"].ToString(); 
        rgContact[cnContact++] = contact; 
       } 
      } 
      return rgContact; 
     } 

     #endregion 

    } 
} 

web.config中WCF的部分

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="httpServiceBehavior"> 
      <serviceMetadata httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="httpEndpointBehavior"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <bindings> 
     <webHttpBinding> 
     <binding name="webHttpBindingWithTransportWindowsSecurity"> 
      <security mode="Transport"> 
      <transport clientCredentialType="Windows" /> 
      </security> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" aspNetCompatibilityEnabled="true" /> 
    <services> 
     <service name="Sid.Skode.Web.Services.Populate.InsuranceClientContactService" behaviorConfiguration="httpServiceBehavior"> 
     <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithTransportWindowsSecurity" 
        contract="Sid.Skode.Web.Services.Populate.IInsuranceClientContactService" 
        behaviorConfiguration="httpEndpointBehavior"> 
     </endpoint> 
     <endpoint 
      address="mex" 
      binding="mexHttpsBinding" 
      bindingConfiguration="" 
      contract="IMetadataExchange"/> 
     </service> 
    </services> 
    </system.serviceModel> 

回答

0

如上所述here,你需要从网络配置中删除RadCompression HTTP模块的所有实例。然后,它的工作。

相关问题