2009-12-07 32 views
0
var store = new FMP.AspNetJsonStore({ 
     fields: [ 
         { name: 'AssetID' }, 
         { name: 'AssociationID' }, 
         { name: 'Image' }, 
         { name: 'StatusName' }, 
         { name: 'ModelName' }, 
         { name: 'IPAddress' }, 
         { name: 'InScope', type: 'boolean' }, 
         { name: 'ServicePlanName' }, 
         { name: 'PricePlanName' }, 
         { name: 'PricePlanDescription' }, 
         { name: 'Program' }, 
         { name: 'ServicePlanID' }, 
         { name: 'Customer' }, 
         { name: 'Black', type: 'float' }, 
         { name: 'Cyan', type: 'float' }, 
         { name: 'Magenta', type: 'float' }, 
         { name: 'Yellow', type: 'float' }, 
         { name: 'BlackPct' }, 
         { name: 'CyanPct' }, 
         { name: 'MagentaPct' }, 
         { name: 'YellowPct' }, 
         { name: 'PrinterMarkerSupplies' }, 
         { name: 'PageCount' }, 
         { name: 'BlackImpressions' }, 
         { name: 'ColorImpressions' }, 
         { name: 'PricePlanID' }, 
         { name: 'ResponsibilityForAction' }, 
         { name: 'PrinterSerialNumber' } 

        ], 

     totalProperty: "TotalCount", 
     autoLoad: { params: { start: 0, limit: myPageSize} }, 
     //autoLoad: true, 
     proxy: new Ext.data.HttpProxy({ 
      // Call web service method using GET syntax 
      url: 'GetPrintersGrid.asmx/buildGrid', 
      // Ask for Json response 
      headers: { 'Content-type': 'application/json' }, 
      method: "GET" 
     }), 
     remoteSort: true, 
     //sortInfo: { field: 'PageCount', direction: "DESC" }, 
     groupField: 'Customer', 
     root: 'Records' 
    }); 

    store.setDefaultSort('PageCount', 'DESC'); 

我正在使用web服務對此進行排序。在網格面板中排序

我得到一個錯誤

{"Message":"Invalid JSON primitive: DESC.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromGetRequest(HttpContext context, JavaScriptSerializer serializer, WebServiceMethodData methodData)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"} 

誰能幫助我在這個問題上

我使用Ext.ux.AspWebServiceProxy類,並應用於store.Also這個代理類中定義的Web服務scriptmanager代理中的用戶控件 Iam使用以下示例作爲參考時出現GetPrintersGrid未定義的錯誤。

http://osman.in/aspnet/using-extjs-grid-with-aspnet-ajax-wcf-webservices-c/

能否請你幫我在這個問題上。

/// <reference path="ExtJS/ext-all.js" /> 

Ext.namespace('Ext.ux'); 

Ext.ux.AspWebServiceProxy = function(conn) 
      { 
       Ext.ux.AspWebServiceProxy.superclass.constructor.call(this); 
       Ext.apply(this, conn); 
      }; 

Ext.extend(Ext.ux.AspWebServiceProxy, Ext.data.DataProxy, 
{ 
    load : function (params, reader, callback, scope, arg) 
      { 
       var userContext = { 
            callback: callback, 
            reader: reader, 
            arg: arg, 
            scope: scope 
           }; 

       var proxyWrapper = this; 

       //Handles the response we get back from the web service call 
       var webServiceCallback = function(response, context, methodName) 
             { 
              proxyWrapper.loadResponse(response, userContext, methodName); 
             } 

       var serviceParams = []; 

       //Convert the params into an array of values so that they can be used in the call (note assumes that the properties on the object are in the correct order) 
       for (var property in params) 
       { 
        serviceParams.push(params[property]); 
       } 

       //Add the webservice callback handlers 
       serviceParams.push(webServiceCallback); 
       serviceParams.push(this.handleErrorResponse); 

       //Make the actual ASP.Net web service call 
       this.webServiceProxyMethod.apply(this.webServiceProxy, serviceParams); 
      }, 

    handleErrorResponse : function(response, userContext, methodName) 
          { 
           alert("Error while calling method: " + methodName + "\n" + response.get_message()); 
          }, 

    loadResponse : function (response, userContext, methodName) 
        { 
         var result = userContext.reader.readRecords(response); 
         userContext.callback.call(userContext.scope, result, userContext.arg, true); 
        } 

}); 

var dataStore = new Ext.data.Store(
        { 
         //Note that I have renamed the web service proxy class 
         proxy: new Ext.ux.AspWebServiceProxy(
         { 
          webServiceProxy: GetPrintersGrid, 
          webServiceProxyMethod: GetPrintersGrid.buildGrid 
         }), 
         remoteSort: true      
        }); 

<asp:ScriptManagerProxy ID="PageScriptManager" runat="server"> 
     <Services> 
      <asp:ServiceReference Path="~/GetPrintersGrid.asmx" /> 
</Services> 
     <Scripts> 
       <asp:ScriptReference Path="~/Ext.ux.AspWebServiceProxy.js" /> 
     </Scripts> 
    </asp:ScriptManagerProxy> 
+0

這仍然不是一個ExtJS問題,但您需要發佈FMP.AspNetJsonStore的源代碼,如果您通過您的服務器問題。 – Upperstage 2009-12-07 18:00:41

+0

實際上,這很可能是一個客戶端代碼問題,因爲服務器錯誤是關於在Web服務調用中從客戶端發送到服務器的** de **序列化JSON。很難說從發佈什麼,但... – 2009-12-08 04:41:49

回答

1

這是烴源代碼我ussed FMP.AspNetJsonReader = Ext.extend(Ext.data.JsonReader,{

 read: function(response) { 
      // Assuming ASP.NET encoding - Data is stored as 
      var json = response.responseText; 
      var o = Ext.decode(json); 
      if (!o) { 
       throw { message: "AspNetJsonReader.read: Json object not found" }; 
      } 
      if (!o.d) { 
       throw { message: "AspNetJsonReader.read: Root element d not found" }; 
      } 
      return this.readRecords(o.d); 

     } 

    }); 

    FMP.AspNetJsonStore = Ext.extend(Ext.data.GroupingStore, { 
     /** 
     * @cfg {Ext.data.DataReader} reader @hide 
     */ 
     constructor: function(config) { 
      FMP.AspNetJsonStore.superclass.constructor.call(this, Ext.apply(config, { 
       reader: new FMP.AspNetJsonReader(config) 
      })); 
     } 
    }); 

蔭使用AS.NET用於服務器端

這裏是我的web服務 public PagedResult buildGrid(int start,int limit,string sortfield,string dir) var a = 5;

Guid AccountID = (Guid)Session["AccountID"]; 
    //string sortdir; 
    //if(dir == "DESC") 
    //{ 
    // sortdir = dir.Substring(0, 4).Trim().ToUpper(); 
    //} 
    //else 
    //{ 
    // sortdir = dir.Substring(0, 3).Trim().ToUpper(); 
    //} 

    string SortExpression = sortfield + " " + (!String.IsNullOrEmpty(dir) ? dir : String.Empty); 

    //string whereClause = "SELECT value a FROM XSP_AssetList_V AS a WHERE a.AccountID = GUID'" + AccountID + "' order by a.PageCount = '" + + "'"; 
    string whereClause = "SELECT value a FROM XSP_AssetList_V AS a WHERE a.AccountID = GUID'" + AccountID + "' Order By a."+SortExpression; 
    //string whereClause = "SELECT value a , ROW_NUMBER() OVER(ORDER BY" + " " + SortExpression + ") As RowNumber FROM XSP_AssetList_V AS a WHERE a.AccountID = GUID'" + AccountID + "'"; 
    //string whereClause = "SELECT value a FROM XSP_AssetList_V AS a WHERE a.AccountID = GUID'" + AccountID + "'"; 
    List<FMPAsset> fmpAssets = new List<FMPAsset>(); 



    using (XSPAssetModel.XSPAssetEntities assetEntities = new XSPAssetEntities(b.BuildEntityConnectionString1("XSMDSN"))) 
    { 
     ObjectQuery<XSP_AssetList_V> assets = new ObjectQuery<XSP_AssetList_V>(whereClause, assetEntities); 
     //var assetOrder = assets.OrderBy(x => x.StatusName).ToList(); 
     var assetPage = assets.Skip(start).Take(limit); 

     //var totalAssetCount = assets.Count(); 



     currentAssets = assetPage.ToList(); 
     int currentAssetsCount = currentAssets.Count; 
     string imgprefix = System.Configuration.ConfigurationManager.AppSettings["ImgPrefix"]; 
     char[] separators = { '/' }; 
     string appname = ""; 
     int lastloc = imgprefix.Substring(0, imgprefix.Length - 1).LastIndexOfAny(separators); 
     if (lastloc > 6) 
     { 
      appname = imgprefix.Substring(lastloc + 1); 
     } 


     FMPAsset asset = new FMPAsset(); 

     //StreamWriter sw = new StreamWriter("C:\\test.txt"); 

     XSPPrinterMarkerSupplyModel.XSPPrinterMarkerSupplyEntities markerCtx = new XSPPrinterMarkerSupplyModel.XSPPrinterMarkerSupplyEntities(b.BuildEntityConnectionString1("XSMDSN")); 

     for (int x = 0; x < currentAssetsCount; x++) 
     { 
      asset = new FMPAsset(); 

      asset.AssetID = currentAssets[x].AssetID.ToString(); 
      asset.PricePlanID = currentAssets[x].PricePlanID.ToString(); 
      asset.AssociationID = currentAssets[x].AssociationID; 
      asset.ModelName = currentAssets[x].ModelName; 
      asset.ResponsibilityForAction = currentAssets[x].ResponsibilityForAction; 
      asset.IPAddress = (String.IsNullOrEmpty(currentAssets[x].PrinterIPAddress)) ? "No IP" : currentAssets[x].PrinterIPAddress; ; 

      if (currentAssets[x].InScope) 
      { 
       asset.InScope = b.GetString("SDE_YES"); 
      } 
      else 
      { 
       asset.InScope = b.GetString("SDE_NO"); 
      } 

      asset = SetStatus(appname, asset, x); 

      asset.PricePlanName = currentAssets[x].Program; 
      asset.PricePlanDescription = currentAssets[x].PricePlanDescription; 
      asset.ServicePlanName = currentAssets[x].ServicePlanName; 

      if (currentAssets[x].PrinterSerialNumber != null) 
      { 
       asset.PrinterSerialNumber = currentAssets[x].PrinterSerialNumber; 
      } 
      else 
      { 
       asset.PrinterSerialNumber = "-"; 
      } 

      //sw.WriteLine("ChargebackDescription: " + DateTime.Now.Millisecond); 
      if (this.b.UseChargebackDescription && !String.IsNullOrEmpty(currentAssets[x].CustomerChargebackDescription) && currentAssets[x].CustomerChargebackDescription != "Generated by OUT Integration") 
      { 
       asset.Customer = currentAssets[x].CustomerChargebackDescription; 

       if (asset.Customer.IndexOf(Environment.NewLine) > -1) 
       { 
        asset.Customer = asset.Customer.Substring(0, asset.Customer.IndexOf(Environment.NewLine)); 
       } 
      } 
      else 
      { 
       asset.Customer = currentAssets[x].CustomerChargeBackEntryName; 
      } 

      if (this.b.UsePricePlanDescription && !String.IsNullOrEmpty(currentAssets[x].PricePlanDescription)) 
      { 
       asset.Program = currentAssets[x].PricePlanDescription; 
       if (asset.Program.IndexOf(Environment.NewLine) > -1) 
       { 
        asset.Program = asset.Program.Substring(0, asset.Program.IndexOf(Environment.NewLine)); 
       } 
      } 
      else 
      { 
       asset.Program = currentAssets[x].Program; 
      } 

      asset.BlackPct = -3; 
      asset.CyanPct = -3; 
      asset.MagentaPct = -3; 
      asset.YellowPct = -3; 

      Guid id = currentAssets[x].AssetID; 

      asset = SetCMYKvalues(asset, x); 

      BuilldImpressionsValues(currentAssets[x], ref asset); 
      fmpAssets.Add(asset); 
     } 

     var totalAssetCount = assets.Count(); 
     var y = new PagedResult<FMPAsset>(); 
     y.Records = fmpAssets; 
     y.TotalCount = totalAssetCount; 
     return y; 


     //   CommonGrid1.BindDataSource(SortByStatusName(fmpAssets)); 


    } 

} 
+0

謝謝;如果您將此問題標記爲Java或SQLServer或其他什麼,您可能會有更多的運氣。您當前的問題(以及以前的問題)是服務器問題 - 無論是使用SQL還是使用Web服務。當你把這個標記爲ExtJS時,很多人不會查看它,也許不會問這個問題會給你一個答案。 – Upperstage 2009-12-07 18:27:26

+4

當然我也會在其他人的標籤。 – xrx215 2009-12-07 18:30:31

+0

嘿 - 好評! :-) – Upperstage 2009-12-07 18:38:03

0

當您的商店打電話給您的Web服務時發生此錯誤。無論發送什麼JSON都由於某種原因無效(或者.NET不認爲它是這樣),因此當ASP.NET嘗試將數據反序列化爲您的方法的有效參數列表時,服務器出錯。我首先會看看Firebug,看看究竟傳遞給服務器的是什麼JSON - 這可能會讓你知道問題是什麼。如果發送的JSON無效,那麼這是一個客戶端/分機問題 - 如果它有效,那麼這是一個.NET問題。