kick it on DotNetKicks.com   Shout it  

Using ExtJs with WCF

Been wanting to get to this part of development for a while now and since I struggled a bit to get this working I thought it would make a good post. With the release of the .NET Framework 3.5 WCF seems to be growing in popularity (or maybe it's just me), but since WCF seems to be the replacement for WebSerivices I figure I need to get to know it.

In my last post on WCF I didn't use any client, other than just pointing the browser window at the service address for an operation with no parameters and a return type of "text/plain". Now that I've done some work with a client, I've found this was not very helpful other than proving that the service was up and could serve up text. I hope this will prove more helpful.

Setting up the service

Let's start by getting a service up and running that we can access from our web page. First, create a new ASP.NET Web Application project in VS 2008. Then add a new "AJAX-enabled WCF Service" item to your project. I'll name mine Ajax.svc.

I don't know about VB.NET (I don't have it installed on my machine), but I found that the item template wasn't listed with the web templates in the "Add new item" dialog box. You can find the item template in the root category "Visual C#", but since I usually use the categories to filter out the long list of items it took me a while to find it.

Once you've created the svc item you'll have 2 new files in your project:
  • Ajax.svc - this is the target for the service. When you reference operations from your client you'll use the path ~/{path to parent folder}/Ajax.svc
  • Ajax.svc.cs - this is where you'll write the service definition. Think of this file as your "code behind" file and define the actual service implementation here. As an aside you can define an interface with the service definition with the attributes applied. You could then have different implementations of the service which all adhere to the defined contract. But we'll just keep things to a minimum here.
You'll also notice, if you look at the project references that you have a couple new references added to your project:
  • System.Runtime.Serialization
  • System.ServiceModel
  • System.ServiceModel.Web

Creating the service definition

In my first WCF post we created a typical "Hello World" service, which took no inputs and returned plain/text output. Here I'd like to accept several parameters and return a custom object. I'd also like to have an operation which will return a collection of objects. This way I hope to document a few of the tricks required to create a more real-world example.

Multiple params/simple return value

The first example uses multiple inputs and returns a single, scalar value. Add the following to the Ajax class in your Ajax.svc.cs file:

[System.ServiceModel.OperationContract]
[System.ServiceModel.Web.WebInvoke(
BodyStyle=System.ServiceModel.Web.WebMessageBodyStyle.WrappedRequest,
RequestFormat=System.ServiceModel.Web.WebMessageFormat.Json,
ResponseFormat=System.ServiceModel.Web.WebMessageFormat.Json,
UriTemplate="/Add")]
public int Add(int a, int b)
{
return a + b;
}

Sorry for not using namespace shortcuts here, but when I'm looking at a howto nothing bugs me more than having to track down the proper namespaces. You shouldn't have to worry about these as the item template for your web service should automatically add the using statements at the head of the file for you.

The method must be public and must have the System.ServiceModel.OperationContract attribute to be exposed as part of the service. We'll focus here on the System.ServiceModel.WebInvoke attribute. You have the option of using the System.ServiceModel.WebGet attribute as well, but I wanted to use WebInvoke here to point out that WebGet will limit you to simple types (int, string, etc) and the http GET method. Using WebInvoke allows you to define parameters using complex, custom types and allows you to use both GET and POST. You can also explicitly limit the operation to just one of http method using the "Method" argument of the WebInvoke attribute.
  • BodyStyle (System.ServiceModel.Web.WebMessageBodyStyle) - You can specify Bare, WrappedRequest, WrappedResponse or Wrapped. The key here is the number and type of your input/output. Bare is used for one or zero simple types. So if your input has no parameters or a single, simple type AND your return value is either "void" or a simple type then you can use Bare. If you only need to wrap one of either the request or response then use the WebMessageBodyStyle specific to what you need (ie. multiple and/or complex params = WrappedRequest; complex return type = WrappedResponse). If you need to wrap both the response AND the request, then "Wrapped" will take care of that.
  • RequestFormat/ResponseFormat (System.ServiceModel.Web.WebMessageFormat) - You really have two options, Json or Xml. If you want to return plain text this will essentially set the request.ContentType for you to whatever you select. I believe the default is probably Xml, but I haven't verified that. Incorrectly using this parameter will result in an error message similar to the following: Operation 'Add' of contract 'Ajax' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
  • Method (System.String) - The default is POST, but you can also set this to GET as long as your RequestFormat can be "Bare".
  • UriTemplate (System.String) - This is what the name of the operation will be when it is exposed with the service. It doesn't have to match the name of the class method. When you reference the operation it will be in the format ~/{path to parent folder}/{service name}.svc/{UriTemplate}. Also, if you want to map your parameters to querystring /post parameters you can do that here as well like this: Add?a={a}&b={b}. And the parameters will map to your method signature. If you are going to use UriTemplate, then you will also want to change replace the <enablewebscript/> behavior in your web.config file with <webhttp/>. Otherwise you'll get this error: Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.

Complex Types

Next, let's add a complex type we can use to meet the goals I stated at the beginning of this post:

[System.Runtime.Serialization.DataContract]
public class Person
{
public Person(String first, String last, Int32 age)
{
FirstName = first;
LastName = last;
Age = age;
}

[System.Runtime.Serialization.DataMember]
public String FirstName { get; set; }
[System.Runtime.Serialization.DataMember]
public String LastName { get; set; }
[System.Runtime.Serialization.DataMember]
public Int32 Age { get; set; }
}

Nothing fancy here, just annotate the class as DataContract and each property to be exposed as DataMember. However, I'd like to mention a small, but important point here. If the class implements System.Runtime.Serialization.ISerializable you don't need to annotate your class with DataContract and DataMember. Just make sure the class properly implements the ISerializable.GetObjectData method and has a constructor with the same signature as GetObjectData.

If you try mixing DataContract with Serializable you'll get an System.Runtime.Serialization.InvalidDataContractException error message like this:

Type 'ExtJsWCF.Person' cannot be ISerializable and have DataContractAttribute attribute.

Now, back to our remaining service operations. Go ahead and add the following to our Ajax service class definition:

[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetPerson")]
public Person GetPerson(String first, String last, Int32 age)
{
return new Person(first, last, age);
}

[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetRelatives")]
public IList<Person> GetRelatives(Person person)
{
System.Collections.Generic.List<Person> people = new System.Collections.Generic.List<Person>();

people.Add(new Person("Joe", person.LastName, 41));
people.Add(new Person("John", person.LastName, 33));
people.Add(new Person("Jane", person.LastName, 30));

return people;
}

[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/SaveRelatives")]
public Boolean SaveRelatives(Person[] people)
{
return true;
}


At this point we should be able to compile our service. Now we're ready for our client.

Setting up the client (ExtJs)

At this point I'm going to go into specifics about ExtJs. Much of what I'll address should be applicable to most clients, but I'll leave those specifics to you.

If you haven't already, you'll want to download the ExtJs sdk. I am using 2.1. Once you've unzipped the archive, you can copy the following files and directories to the root of our application:
  • /ext-all.js
  • /adapter/
  • /resources/
Now open Default.aspx and add the following to the <head> element:

<link href="extjs/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script src="extjs/adapter/ext/ext-base.js" type="text/javascript"></script>
<script src="extjs/ext-all.js" type="text/javascript"></script>

<style>
.myForm {
margin: 3em;
}
.myResponse
{
color: Red;
font-weight: bold;
}
</style>
<script type="text/javascript">
var mask;

Ext.onReady(function(){
Ext.get('btnSum').on('click', addValues);
Ext.get('btnGetPerson').on('click', getPerson);
Ext.get('btnGetFamily').on('click', getFamily);

mask = new Ext.LoadMask(Ext.getBody(), {
msg: "Loading..."
});

});

function addValues()
{
mask.show();

var aVal = Ext.get('txtA').dom.value;
var bVal = Ext.get('txtB').dom.value;

var params = { a : aVal, b : bVal };

Ext.lib.Ajax.defaultPostHeader = 'application/json';

Ext.Ajax.request({
url: '/Ajax.svc/Add',
method: 'POST',
params : Ext.encode(params),
success: function(response,options){
mask.hide();
Ext.get('txtResult').dom.value = response.responseText;
Ext.get('additionResponse').dom.innerHTML = response.responseText;
},
failure: function(response,options){
mask.hide();
Ext.MessageBox.alert('Failed', 'Unable to add values');
}
});
}

function getPerson()
{
//status display
mask.show();

//get form values
var fVal = Ext.get('txtFirst').dom.value;
var lVal = Ext.get('txtLast').dom.value;
var aVal = Ext.get('txtAge').dom.value;

//create Json object
var params = { first: fVal, last: lVal, age: aVal };

//change post header from application-x-urlencoded
Ext.lib.Ajax.defaultPostHeader = 'application/json';

//create request
Ext.Ajax.request({
url: '/Ajax.svc/GetPerson',
params: Ext.encode(params),
method: 'POST',
success: function(response,options){
// response callback

//update status display
mask.hide();

// display literal output from response
Ext.get('getPersonResponse').dom.innerHTML = response.responseText;

// decode text into Json object
var data = Ext.decode(response.responseText);

// display data from object
Ext.MessageBox.alert('First: ' + data.GetPersonResult.FirstName
+ '<br>Last: ' + data.GetPersonResult.LastName
+ '<br>Age: ' + data.GetPersonResult.Age);
},
failure: function(response,options){
mask.hide();
Ext.MessageBox.alert('Failed', 'Unable to get person');
}
});
}


function getFamily()
{
//status display
mask.show();

//get form values
var fVal = Ext.get('txtFirst').dom.value;
var lVal = Ext.get('txtLast').dom.value;
var aVal = Ext.get('txtAge').dom.value;

//create Json object
var params = { person: { FirstName: fVal, LastName: lVal, Age: aVal } };

//change post header from application-x-urlencoded
Ext.lib.Ajax.defaultPostHeader = 'application/json';

//create request
Ext.Ajax.request({
url: '/Ajax.svc/GetRelatives',
params: Ext.encode(params),
method: 'POST',
success: function(response,options){
// response callback

//update status display
mask.hide();

// display literal output from response
Ext.get('getPeopleResponse').dom.innerHTML = response.responseText;

// decode text into Json object
var data = Ext.decode(response.responseText);

// display data from object
var store = new Ext.data.JsonStore({
data : data,
root : 'GetRelativesResult',
fields: [
{name: 'FirstName'},
{name: 'LastName'},
{name: 'Age'}
]
});

Ext.get('persongrid').dom.innerHTML = '';

var family = new Ext.grid.GridPanel({
store : store,
colums : [
{id: 'FirstName', header: 'Name', dataIndex: 'FirstName'},
{id: 'LastName', header: 'Last Name', dataIndex: 'LastName'},
{id: 'Age', header: 'Age', dataIndex: 'Age'}
],
title : 'Family',
autoHeight: true
});

family.render('persongrid');
},
failure: function(response,options){
mask.hide();
Ext.MessageBox.alert('Failed', 'Unable to get family');
}
});
}

</script>

An add this to the <body> element of the page:

<div>
<div id="addition" class="myForm">
<div>A: <input id="txtA" type="text" size="3" maxlength="3" /></div>
<div>
B: <input id="txtB" type="text" size="3" maxlength="3" />
<input id="btnSum" type="button" value="sum" />
</div>
<div>Answer: <input id="txtResult" type="text" size="5" /></div>
<div>Http Response text:<div id="additionResponse" class="myResponse"></div></div>
</div>

<div id="personform" class="myForm">
<div>First Name: <input id="txtFirst" type="text" /></div>
<div>Last Name: <input id="txtLast" type="text" /></div>
<div>
Age: <input id="txtAge" type="text" maxlength="2" size="3" />
<input type="button" id="btnGetPerson" value="Get" />
<input type="button" id="btnGetFamily" value="Get Family" />
</div>
<div>Http Response text:<div id="getPersonResponse" class="myResponse"></div></div>
</div>

<div class="myForm">
<div id="persongrid"></div>
<div>Http Response text:<div id="getPeopleResponse" class="myResponse"></div></div>
</div>
</div>


Now load the page in your browser and give it a whirl!

Here's what you'll notice as you play with the page:
  • The Json in the request body needs to be encoded by placing quotes around each identifier as well as any string values.
  • The response from the Add method is just plain text, no quotes, no Json notation.
  • When the response is wrapped the root name of the object is the name of the WCF operation plus the text "Result". Make sure and account for that when working with the objects. I'm still looking for a way to control that value, but for now I'm just using the javascript String.Replace function like this: new String(response.responseText).replace(/MethodNameResult/, "whatIWantHere");
  • The Json response comes across the wire encoded, so you'll need to decode the object to work with it.
  • Date values are serialized by the service as "/Date(1235468858)/" where 1235468858 is the number of ticks from January 1, 1970. The problem with this is in order for this date to work (at least with ExtJs) it needs to be "/new Date(1235468858)/". To achive this you can use a regex to insert it. Here's what I'm using: var exp = response.responseText.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+(-[0-9]+)?)\\)\\\\/\\"', 'g'), "$1new Date($2)");
  • When sending an array to the service from the client an important thing to know is that sending just the array isn't enough. It seems natural just to send the array. But if you were to send the encoded array, you'll get the following error: OperationFormatter encountered an invalid Message body. Expected to find an attribute with name 'type' and value 'object'. Found value 'array'. Make sure that you encode your array as a property of a Json object, like this: Ext.encode({parameterName: myArray});.

Conclusion

This post is a result of hours of frustration and digging, so I hope it helps someone save some time and avoid the traps I ran into.

Tags: ,

kick it on DotNetKicks.com   Shout it  

Feedback

# 

Gravatar Impressive work Mark. 7/17/2008 2:17 PM | noreply@blogger.com (Anonymous)

# 

Gravatar Thanks! 7/17/2008 2:23 PM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Thanks! I have been struggling a bit with ext js and data services myself and your post is a great resource. I have been dealing with a problem you might have encountered as well. When I send a POST request to a service operation everything seems to be working correctly but for some reasons the parameters are passed as null when I debug on the data service. Do you happen to have any idea why? The payload of the POST looks just fine... 7/18/2008 2:53 AM | noreply@blogger.com (Aurelien)

# 

Gravatar I did have the same problem. I wasn't using Ext.encode. So if you have a Json object like this:

var data = {param1: "value", param2: "value2"};

You need to encode it like this:

var encodedData = Ext.encode(data);

Then, when you see it in the payload it will look like this:

{"param1": "value", "param2":"value2"}

The Json data returned from your operation will also be encoded, so just decode it when it comes back to you by calling decode like this:

var data = Ext.decode(response.responseText);

Then assuming the data you get back is a complex object with a property named 'FirstName' you can use it like this:

data.MyOperationResult.FirstName

Hope that helps. 7/18/2008 4:52 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Mark -

Great post on how to .NET's WCF with Ext. I'd love to see some more posts detailing the integration points between Ext.data.Store's and Ext.tree.TreePanel's. Keep up the great work!

Aaron Conran
Ext JS Core Developer 9/23/2008 7:30 PM | noreply@blogger.com (eaconran)

# 

Gravatar Very well written example.
However, I get:
'Failed', 'Unable to add values'
every time.

Its as if the AJAX call is failing every time. Any ideas why? 10/11/2008 3:54 PM | noreply@blogger.com (Anonymous)

# 

Gravatar Most likely there is a problem with your WCF service. The error is just a generic one. You can change the message to display the actual error message by using response.responseText as the text of the alert.

Or set a break point using the Firebug plugin for Firefox. You'll get the real error message and that should tell you what's going wrong. 10/13/2008 8:56 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar All the above examples use Json as the request message format.
Is there any documentation anywhere on how to format the request payload for Method="POST", BodyStyle=WrappedRequest, RequestFormat=Xml?
I need to know how format the xml payload for a service method with multiple parameters.
Thanks in advance... 10/30/2008 8:20 AM | noreply@blogger.com (Rey)

# 

Gravatar -------------------
-------------------
"Most likely there is a problem with your WCF service. The error is just a generic one. You can change the message to display the actual error message by using response.responseText as the text of the alert.

Or set a break point using the Firebug plugin for Firefox. You'll get the real error message and that should tell you what's going wrong."
-------------------
-------------------

You were right, I fixed it using Firebug and Web Development Helper.

Thanks again for this article. 11/1/2008 3:48 PM | noreply@blogger.com (Anonymous)

# 

Gravatar Sorry it took me so long to get back to you. I haven't actually tinkered with using RequestFormat.Xml as of yet since I've only been working with Ajax and IMHO JSON just makes more sense in this scenario. But I did look around a bit because I was curious and I did find a couple links. But given that most AJAX examples are going to be using JSON it did take a bit of looking around to find what I was looking for.

If you are looking for how to format the soap message, here's an example using Ajax. It's not using ExtJs, but you should be able to make the translation: www.vishwamohan.com/.../>If you're wanting POX (Plain Old Xml) it appears to be much more difficult. However, I did find a very involved example done by Clemens Vasters. It is a 9 part series. However, the links to the next part of the series aren't always there, so I'm giving you the link to part 9 which has the links to parts 1-8 in the intro so you can read them all. But it seems like overkill if you ask me.

staff.newtelligence.net/.../...e-ad7110dee188.aspx 11/3/2008 8:34 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Curiosity drove me to run a couple more searches. Here are a couple MSSN results on WCF and POX:

REST and POX - msdn.microsoft.com/.../>Web Programming Model - msdn.microsoft.com/en-us/library/bb412169.aspx 11/3/2008 9:12 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Hi Mark, could you please post your web.config file? I had a lot of problems to leave the application working.

Now my problem is that the debugger does not get inside on 'success' of ajax request. The error is "End point not found"

Could you help me
Diego 11/4/2008 10:48 AM | noreply@blogger.com (dschonhals)

# 

Gravatar dschonhals,

can you browse to your service using Firefox or IE? (ex. www.mydomain.com/myservicedirectory/myservice.svc or http://localhost/....). You might be getting a 404 error which is common if you are using a hosting service. The problem has to do with having more than one host headers defined in IIS. If you get a 404 when you try to browse to your service then you'll need to create a custom ServiceHostFactory and override the CreateServiceHost method.

Here's an example of a custom ServiceHost:

public class CustomHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost ( Type serviceType, Uri[] baseAddresses )
{
Uri address = baseAddresses[0];
if(baseAddresses.length > 1)
address = new Uri("www.mydomain.com/.../MyService.svc");

CustomHost customServiceHost =
new CustomHost( serviceType, address );
return customServiceHost;
}
}

public class CustomHost : ServiceHost
{
public CustomHost ( Type serviceType, params Uri[] baseAddresses )
: base( serviceType, baseAddresses )
{ }

protected override void ApplyConfiguration ()
{
base.ApplyConfiguration();
}
}

And your .svc file should look like this:

<%@ ServiceHost Language="C#" Debug="true" Service="MyNamespace.MyService" Factory="MyNamespace.MyServiceHostFactory" CodeBehind="MyService.svc.cs" %> 11/5/2008 8:31 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Hi Mark.

Great article. I have been playing a lot with WCF and know making implementations using REST architecture. After the .NET freamework 3.5 SP1 I noticed that using the "enableWebScript" tag was not allowed when using UriTemplate parameter for WebGet/WebInvoke. I found out (thanks to your post and other articles) that I could make JSon notation to work on my service by adding the ResponseFormat=WebMessageFormat.Json, however this makes my service to always return a JSon response loosing the "implement once, serve many" concept. What I want to do is to have one service and be able to deliver the data in many different formats (SOAP, XML and JSON). Is there any way to achieve this without using the ResponseFormat=WebMessageFormat.Json?

Thanks
-aB 12/17/2008 4:00 PM | noreply@blogger.com (Anthony Baker [arbbot])

# 

Gravatar Here's a link I ran across a while back. I intended to try it out, but haven't gotten around to it. Check it out and let me know if it worked for you:

www.codemeit.com/.../...json-and-soap-coexist.html 12/17/2008 4:04 PM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar I have the same problem like Anonymous:


However, I get:
'Failed', 'Unable to add values'
every time.


I changed the message to display the actual error message by using response.responseText as the text of the alert, but

response.responseText = "" !

I try ecexute service like

localhost:36248/.../>and result is

Method not allowed. 1/17/2009 4:24 PM | noreply@blogger.com (Anonymous)

# 

Gravatar Sorry I took so long to get back to you. Basically your issue is somewhere in your WCF portion. It may be in your web.config. But unfortunately you haven't provided enough information to provide a solution. But this error is a common one and you should be able to find a solution on google:

www.google.com/.../>I hope this helps. 1/28/2009 9:33 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar I came across your article in my search for how to customize the name of the wrapped result object returned from WCF. You mentioned that you were looking for a similar solution and working around it, so I thought I'd pass along what I found.

After some serious digging, I've found that you can customize it by applying the MessageParameter attribute to the return value of the operation like this:

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
[return:MessageParameter(Name = "myFoo")]
public string GetFoo() {return "foo";}

This method will now return
{"myFoo":"foo"}
as the wrapped response.

Best,
Chris 2/2/2009 6:17 PM | noreply@blogger.com (Chris)

# 

Gravatar Chris, thanks! I appreciate you following up and posting the solution. 2/2/2009 8:11 PM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Hello, guys, thanks for a nice article. But I have a problem - when I try to pass parameters to WCF service method, I get error 400 every time. Calling other methods that don't have parameters work well.

What could be the problem? What binding settings should be specified for the service? 4/12/2009 6:30 AM | noreply@blogger.com (Kyrylo)

# 

Gravatar The example here uses the default bindings that are created when you add a svc file to your web project, to get this to work you shouldn't have to modify them.

If you like, send me the relevant code and I'll take a peek at it. My email is developmentalmadness and is a gmail account. 4/13/2009 7:29 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Kyrylo,

I fiddled around with this a while today and so far I've come up with a couple things. If you haven't already done so, I suggest you get the Firebug plugin for Firefox to get a good look at what's going on behind the scenes. This will also let you see the error message and stack trace coming back from ASP.NET.

First, when you encode your params the JsonStore doesn't send anything in the post. This may be because JsonStore is trying to encode it and do something with it in the background. I found if you don't encode the params JsonStore will then add the params to the post, but not as a Json object. That's the second issue, I seem to remember fiddling with this quite a bit when I was first trying to figure this out. Ext.ajax.Request seems like it was the only method I could get to properly POST my parameters as a JSON object. Yes, there are a lot of nice ways ExtJs puts this all together for you so you can easily POST your web request. However, it seems like most of the time it expects to be POSTing to a server using the RFC POST standard and not as a raw JSON object.

I really don't have the knowledge to dig into ExtJs and figure out what they are doing, but I'd suggest trying the Ext.ajax.Request first and see if that solves your problem. 4/16/2009 3:32 PM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Mark,

I managed to find the solution for passing params via JSON Store. Yes, as you had said, in some reasons encoded params do not pass to the request, so we have empty post data, what caused an error.

But we can set any params we need just before store loading, like this:

gridConfig.store.on('beforeload', function(sender, options){
options.params = Ext.encode({
showActive: btnShowActive.pressed,
showDisabled: btnShowDisabled.pressed,
showDeleted: btnShowDeleted.pressed
});
});


and voila! Everything works !! 4/24/2009 9:19 AM | noreply@blogger.com (Kyrylo)

# 

Gravatar Hi !

This is the very best atricle and sample I found, especially for the case, that I would like to start with extjs .... But:Sorry, I am not able to make it running at all. There are problems with the WCF service .... Is it possibly for you [please!] to put a project to download onto your blog here??? Would be really great!

br--mabra 4/27/2009 4:08 PM | noreply@blogger.com (Anonymous)

# re: Using ExtJs with WCF

Gravatar Hello everyone, as I was digging around to find a solution to my problem (extjs + Wcf) I stumbled with this article. Thank for creating this it has been a eye opening experience using extjs with WCF.

As I was using this article I noticed that the author assumes that the extjs program will be written where the web service is created; in other words within the same domain name.

But what if the WCF service is hosted within you own company but on a different server?

I have been trying multiple given solutions and none of them work.

Has anyone tried this? Has it work? If you have, can you please post a peace of your code to help me out.
3/12/2010 12:04 PM | Rey

Post a comment





 

Please add 6 and 3 and type the answer here:

 

 

Copyright © Mark J. Miller