-
21 Feb 2012 10:25 AM #1
Answered: Store proxy calling asp.net asmx webservice
Answered: Store proxy calling asp.net asmx webservice
The following code works to call a .net webservice
The following code uses a store proxy to call the same .net webservice, but does not workCode:Ext.Ajax.request({ headers: { 'Content-Type': 'application/json; charset=utf-8' }, method: 'POST', url: 'Services.asmx/MyWebservice', success: function (response) { //load my store with json formatted data returned in response.responseText } });
Does anyone have experience/success in calling an asp.net webservice using the proxy on a store?Code:var theStore = Ext.create('Ext.data.Store', { model: 'App.model.RequestNotesItem', proxy: { type: 'ajax', url: 'Services.asmx/MyWebService', headers: { 'Content-Type': 'application/json; charset=utf-8' }, actionMethods: { create: 'POST', read: 'POST', update: 'POST', destroy: 'POST' } } }); theStore.load();
-
Best Answer Posted by mitchellsimoens
What does the JSON look like? Do you need to configure the reader?
-
21 Feb 2012 10:37 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3157
What does the JSON look like? Do you need to configure the reader?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Feb 2012 12:16 PM #3
I had to add these to the proxy to make it return json successfully
Here is a sample of the json returned.Code:reader: { type: 'json', root: 'd' }, writer: { encodeRequest: true, type: 'json' }
{"d":"[{\"note_id\":165,\"added_date\":\"2/16/2012 5:03:16 PM\",\"added_by_name\":\"Person1\",\"note_text\":\"and yet another\"},{\"note_id\":164,\"added_date\":\"2/16/2012 5:01:42 PM\",\"added_by_name\":\"Person2\",\"note_text\":\"aabc dd eff lorem ipsum\"}]"}
.net wraps it in a "d" for security reasons.
**UPDATE**
This thread got mistakenly marked as answered, but it's not answered. I wasn't sure how to set it back. I'm getting a json response, but it isn't loading the store correctly.
-
22 Feb 2012 12:38 PM #4
I found my problem. The asp.net asmx service I was using to return json was returning a json string. So it looks like the proxy reader cannot read that json string. I changed to a asp.net wcf service and return a json object through a Stream instead of returning a string (found a bunch of examples of this on google). The store loads the data correctly this way. Hope this helps some fellow asp.net people.


Reply With Quote