使用json端点从extjs传递参数到RIA服务

时间:2012-03-30 07:29:57

标签: extjs4 ria

我正在尝试使用POST通过extjs与RIA服务进行通信,以获得以下代码的响应。

var store = Ext.create('Ext.data.Store', {
                        model: 'RootResults',
                        proxy: {
                            type: 'ajax',
                            actionMethods: 'POST',
                            url: 'MyService.svc/JSON/GetRes',
                            headers: {
                                'Content-type': 'application/json' 
                            },
                            reader: {
                                type: 'json',
                                root: 'GetResResult.RootResults',
                                totalProperty: 'GetResResult.TotalCount'
                            }
                            , pageParam: undefined,
                            startParam: undefined,
                            limitParam: undefined

                            , success: function (response) {
                                alert(response);

                            }

                        }
                    });

     var operation = new Ext.data.Operation({
          FId: 1,
          SId: 0
      });

 store.load({ params: Ext.encode(operation) });

我可以用get访问它。 当我尝试使用POST时,它返回错误 - “405 Method Not Allowed”。 如何使其启用POST?

2 个答案:

答案 0 :(得分:1)

当我问这个问题时,我对extjs和RIA服务之间的POST通信感到困惑。

我在以下文章的帮助下解决了这个问题 http://www.joseph-connolly.com/blog/post/WCF-RIA-Services-jQuery-and-JSON-endpoint-Part-2.aspx

为了从jquery或extjs访问WCF RIA服务,实际上我们需要为CUD(Create-Update-Delete)操作创建changeset,并且所有操作都使用JSON / SubmitChanges。

答案 1 :(得分:0)

我相信在服务器端你需要将HasSideEffects添加到方法声明()中:

[Invoke(HasSideEffects = true)]
public GetPages(...)
{

}