第一节:ExtJS调用WCF系列-----实现JSON传递

首先我们打开我们的VS 新建一个Asp.Net WebApplication Project,(不要给我说新建网站,我讨厌那个东东) 命名为ExtJSAndWCFChapter1 如图:
第一节:ExtJS调用WCF系列-----实现JSON传递
接下来我们在该项目中新建一个实体类文件和一个AJAX—Enabled WCF SERVICE,分别命名为Employee.cs 和EmployeeService.svc
第一节:ExtJS调用WCF系列-----实现JSON传递
下面去ExtJS.Com网站下载一个ExtJS 2.0 ,解压缩后拷贝至Default.aspx相同目录下,并包括在项目中。如图:
第一节:ExtJS调用WCF系列-----实现JSON传递
下面开始编写代码:先编写Employee.cs的代码,代码如下:
第一节:ExtJS调用WCF系列-----实现JSON传递using System;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Data;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Configuration;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Linq;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Web;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Web.Security;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Web.UI;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Web.UI.HtmlControls;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Web.UI.WebControls;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Web.UI.WebControls.WebParts;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Xml.Linq;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Runtime.Serialization;
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递
namespace ExtJSAndWCFChapter1
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递    [DataContract]
第一节:ExtJS调用WCF系列-----实现JSON传递    
public class Employee
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递    
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            [DataMember]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
public Guid EmployeeID 第一节:ExtJS调用WCF系列-----实现JSON传递setget; }
第一节:ExtJS调用WCF系列-----实现JSON传递            [DataMember]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
public string CnName 第一节:ExtJS调用WCF系列-----实现JSON传递setget; }
第一节:ExtJS调用WCF系列-----实现JSON传递            [DataMember]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
public bool Sex 第一节:ExtJS调用WCF系列-----实现JSON传递setget; }
第一节:ExtJS调用WCF系列-----实现JSON传递            [DataMember]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
public int Age 第一节:ExtJS调用WCF系列-----实现JSON传递setget; }
第一节:ExtJS调用WCF系列-----实现JSON传递            [DataMember]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
public DateTime Birthday 第一节:ExtJS调用WCF系列-----实现JSON传递setget; }
第一节:ExtJS调用WCF系列-----实现JSON传递            [DataMember]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
public string Email 第一节:ExtJS调用WCF系列-----实现JSON传递setget; }
第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递    }

第一节:ExtJS调用WCF系列-----实现JSON传递}

第一节:ExtJS调用WCF系列-----实现JSON传递

接下来编写EmployeeService.cs的代码,代码如下:
第一节:ExtJS调用WCF系列-----实现JSON传递using System;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Linq;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Runtime.Serialization;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.ServiceModel;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.ServiceModel.Activation;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.ServiceModel.Web;
第一节:ExtJS调用WCF系列-----实现JSON传递
using System.Collections.Generic;
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递
namespace ExtJSAndWCFChapter1
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递    [ServiceContract(Namespace 
= "")]
第一节:ExtJS调用WCF系列-----实现JSON传递    [AspNetCompatibilityRequirements(RequirementsMode 
= AspNetCompatibilityRequirementsMode.Allowed)]
第一节:ExtJS调用WCF系列-----实现JSON传递    
public class EmployeeService
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递    
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递        
// Add [WebGet] attribute to use HTTP GET
第一节:ExtJS调用WCF系列-----实现JSON传递
        [OperationContract]
第一节:ExtJS调用WCF系列-----实现JSON传递        
public void DoWork()
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            
// Add your operation implementation here
第一节:ExtJS调用WCF系列-----实现JSON传递
            return;
第一节:ExtJS调用WCF系列-----实现JSON传递        }

第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递        
// Add more operations here and mark them with [OperationContract]
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递
        /**//// <summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// 创建一个实体,实体由客户端传递
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// </summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <param name="emp"></param>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <returns></returns>

第一节:ExtJS调用WCF系列-----实现JSON传递        [OperationContract]
第一节:ExtJS调用WCF系列-----实现JSON传递        [WebInvoke(BodyStyle 
= WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Create")]  
第一节:ExtJS调用WCF系列-----实现JSON传递        
public Guid Create(Employee emp)
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            NotNull(emp.CnName, 
"CnName");
第一节:ExtJS调用WCF系列-----实现JSON传递            
return Guid.NewGuid();
第一节:ExtJS调用WCF系列-----实现JSON传递        }

第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
/**//// <summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// 获取一个实体
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// </summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <param name="id"></param>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <returns></returns>

第一节:ExtJS调用WCF系列-----实现JSON传递        [OperationContract]
第一节:ExtJS调用WCF系列-----实现JSON传递        [WebInvoke(BodyStyle 
= WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Get")]
第一节:ExtJS调用WCF系列-----实现JSON传递        
public Employee Get(int id)
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            
if (id != 1throw new ArgumentException("Expected 1 for ID");
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
return new Employee() 第一节:ExtJS调用WCF系列-----实现JSON传递{ EmployeeID = Guid.NewGuid(), CnName = "Xiaozhuang", Sex = true, Age = 28, Email = "[email protected]", Birthday = new DateTime(19790202) };
第一节:ExtJS调用WCF系列-----实现JSON传递        }

第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
/**//// <summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// 获取所有实体
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// </summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <returns></returns>

第一节:ExtJS调用WCF系列-----实现JSON传递        [OperationContract]
第一节:ExtJS调用WCF系列-----实现JSON传递        [WebInvoke(BodyStyle 
= WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetAll")]
第一节:ExtJS调用WCF系列-----实现JSON传递        
public List<Employee> GetAll()
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            
return new List<Employee>
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递                
new Employee()第一节:ExtJS调用WCF系列-----实现JSON传递{EmployeeID = Guid.NewGuid(),CnName="CnName",Sex=true,Age=28,Email="[email protected]",Birthday=new DateTime(1979,02,02)},
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递                
new Employee()第一节:ExtJS调用WCF系列-----实现JSON传递{EmployeeID = Guid.NewGuid(),CnName="CnName1",Sex=false,Age=28,Email="[email protected]",Birthday=new DateTime(1979,02,02)}
第一节:ExtJS调用WCF系列-----实现JSON传递            }
;
第一节:ExtJS调用WCF系列-----实现JSON传递        }

第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
/**//// <summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// 获取num个实体
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// </summary>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <param name="num"></param>
第一节:ExtJS调用WCF系列-----实现JSON传递        
/// <returns></returns>

第一节:ExtJS调用WCF系列-----实现JSON传递        [OperationContract]
第一节:ExtJS调用WCF系列-----实现JSON传递        [WebInvoke(BodyStyle 
= WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetByNum")]
第一节:ExtJS调用WCF系列-----实现JSON传递        
public List<Employee> GetByNum(int num)
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            
if (num.ToString() == ""throw new ArgumentException("参数错误!");
第一节:ExtJS调用WCF系列-----实现JSON传递            List
<Employee> emplist = new List<Employee>();
第一节:ExtJS调用WCF系列-----实现JSON传递            
for (int i = 1; i <= num; i++)
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递            
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递                Employee emp 
= new Employee() 第一节:ExtJS调用WCF系列-----实现JSON传递{ EmployeeID = Guid.NewGuid(), CnName = i + "CnName", Sex = true, Age = i * 10, Email = i + "[email protected]", Birthday = new DateTime(19790202) };
第一节:ExtJS调用WCF系列-----实现JSON传递                emplist.Add(emp);
第一节:ExtJS调用WCF系列-----实现JSON传递            }

第一节:ExtJS调用WCF系列-----实现JSON传递            
return emplist;
第一节:ExtJS调用WCF系列-----实现JSON传递        }

第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递        
private static void NotNull<T>(T o, string paramName) where T : class
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递        
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递            
if (o == nullthrow new ArgumentNullException(paramName);
第一节:ExtJS调用WCF系列-----实现JSON传递        }

第一节:ExtJS调用WCF系列-----实现JSON传递    }

第一节:ExtJS调用WCF系列-----实现JSON传递}

第一节:ExtJS调用WCF系列-----实现JSON传递

主要就是这一句        [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Create")] 
意思就是说这个方法传递输入和输出参数都是Json形式,并且可以用后面加Create的形式来访问该方法,至于前面那个BodyStyle = WebMessageBodyStyle.Wrapped是什么意思留着下节详细说明

接下来修改Web.Config文件,其实只是是把<enableWebScript /> 替换为<webHttp/>代码如下(一部分)


第一节:ExtJS调用WCF系列-----实现JSON传递<system.serviceModel>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<behaviors>
第一节:ExtJS调用WCF系列-----实现JSON传递            
<endpointBehaviors>
第一节:ExtJS调用WCF系列-----实现JSON传递                
<behavior name="ExtJSAndWCFChapter1.EmployeeServiceAspNetAjaxBehavior">
第一节:ExtJS调用WCF系列-----实现JSON传递                    
<!--<enableWebScript />-->
第一节:ExtJS调用WCF系列-----实现JSON传递                    
<webHttp/>
第一节:ExtJS调用WCF系列-----实现JSON传递                
</behavior>
第一节:ExtJS调用WCF系列-----实现JSON传递            
</endpointBehaviors>
第一节:ExtJS调用WCF系列-----实现JSON传递        
</behaviors>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<services>
第一节:ExtJS调用WCF系列-----实现JSON传递            
<service name="ExtJSAndWCFChapter1.EmployeeService">
第一节:ExtJS调用WCF系列-----实现JSON传递                
<endpoint address="" behaviorConfiguration="ExtJSAndWCFChapter1.EmployeeServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="ExtJSAndWCFChapter1.EmployeeService"/>
第一节:ExtJS调用WCF系列-----实现JSON传递            
</service>
第一节:ExtJS调用WCF系列-----实现JSON传递        
</services>
第一节:ExtJS调用WCF系列-----实现JSON传递    
</system.serviceModel>

现在可以编译并访问那个EmployeeService.svc文件,后面加上UriTemplate的值:例如http://localhost:1481/EmployeeService.svc/get。会得到“Method not allowed”的提示。如果访问出现错误,请确认修改的Web.Config是否正确。
接下来编写Default.aspx的代码:代码如下
第一节:ExtJS调用WCF系列-----实现JSON传递<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ExtJSAndWCFChapter1._Default" %>
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递
<html xmlns="http://www.w3.org/1999/xhtml" >
第一节:ExtJS调用WCF系列-----实现JSON传递
<head runat="server">
第一节:ExtJS调用WCF系列-----实现JSON传递    
<title>Untitled Page</title>
第一节:ExtJS调用WCF系列-----实现JSON传递    
<link rel="stylesheet" type="text/css" href="ExtJS/resources/css/ext-all.css" />
第一节:ExtJS调用WCF系列-----实现JSON传递    
<!-- GC -->
第一节:ExtJS调用WCF系列-----实现JSON传递    
<!-- LIBS -->
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递    
<script type="text/javascript" src="ExtJS/adapter/ext/ext-base.js"></script>
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递    
<script type="text/javascript" src="ExtJS/ext-all-debug.js"></script>
第一节:ExtJS调用WCF系列-----实现JSON传递    
<script type="text/javascript" src="ExtJS/ext-all.js"></script>
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递    
<!-- ENDLIBS -->
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递    
<script type="text/javascript" language="javascript">
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     Ext.onReady(function() 
第一节:ExtJS调用WCF系列-----实现JSON传递{  
第一节:ExtJS调用WCF系列-----实现JSON传递     
//设置Content-Type为application/json形式
第一节:ExtJS调用WCF系列-----实现JSON传递
     Ext.lib.Ajax.defaultPostHeader = 'application/json';
第一节:ExtJS调用WCF系列-----实现JSON传递     
//访问失败的统一回调函数
第一节:ExtJS调用WCF系列-----实现JSON传递
     var onFailure = function(r, opts)
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     
第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递      Ext.
get("errors").insertHtml('afterend''<br/><br/>' + r.responseText, false);  
第一节:ExtJS调用WCF系列-----实现JSON传递    }

第一节:ExtJS调用WCF系列-----实现JSON传递    
//客户端创建一个实体
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递
    var request=第一节:ExtJS调用WCF系列-----实现JSON传递{
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递    emp:
第一节:ExtJS调用WCF系列-----实现JSON传递{     CnName:'xiaozhuang',
第一节:ExtJS调用WCF系列-----实现JSON传递              Sex:
1,
第一节:ExtJS调用WCF系列-----实现JSON传递              Age:
28,
第一节:ExtJS调用WCF系列-----实现JSON传递              Birthday:
'/Date(62831853071)/',
第一节:ExtJS调用WCF系列-----实现JSON传递              Email:
'[email protected]'
第一节:ExtJS调用WCF系列-----实现JSON传递    }

第一节:ExtJS调用WCF系列-----实现JSON传递    }

第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递    Ext.Ajax.request(
第一节:ExtJS调用WCF系列-----实现JSON传递{  
第一节:ExtJS调用WCF系列-----实现JSON传递    url: 
'/EmployeeService.svc/Create',//要访问的方法地址
第一节:ExtJS调用WCF系列-----实现JSON传递
     method: 'POST'
第一节:ExtJS调用WCF系列-----实现JSON传递     
params: Ext.util.JSON.encode(request), //把输入参数进行JSON编码
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递
     success: function(response, options) 第一节:ExtJS调用WCF系列-----实现JSON传递{ Ext.get('create-p').update(response.responseText);  }//输出方法返回结果
第一节:ExtJS调用WCF系列-----实现JSON传递
     failure: onFailure 
第一节:ExtJS调用WCF系列-----实现JSON传递     }
);
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     Ext.Ajax.request(
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递     url: 
'/EmployeeService.svc/Get'
第一节:ExtJS调用WCF系列-----实现JSON传递     method: 
'POST'
第一节:ExtJS调用WCF系列-----实现JSON传递     
params: Ext.util.JSON.encode(1),
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     success: function(response, options) 
第一节:ExtJS调用WCF系列-----实现JSON传递{ Ext.get('get-p').update(response.responseText); }
第一节:ExtJS调用WCF系列-----实现JSON传递     failure: onFailure 
第一节:ExtJS调用WCF系列-----实现JSON传递     }
);
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     Ext.Ajax.request(
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递     url: 
'EmployeeService.svc/GetAll'
第一节:ExtJS调用WCF系列-----实现JSON传递     method: 
'POST',  
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     success: function(response, options) 
第一节:ExtJS调用WCF系列-----实现JSON传递{ Ext.get('getall-p').update(response.responseText);}
第一节:ExtJS调用WCF系列-----实现JSON传递     failure: onFailure 
第一节:ExtJS调用WCF系列-----实现JSON传递     }
); 
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     Ext.Ajax.request(
第一节:ExtJS调用WCF系列-----实现JSON传递
第一节:ExtJS调用WCF系列-----实现JSON传递     url: 
'EmployeeService.svc/GetByNum'
第一节:ExtJS调用WCF系列-----实现JSON传递     method: 
'POST',  
第一节:ExtJS调用WCF系列-----实现JSON传递     
params: Ext.util.JSON.encode(8),
第一节:ExtJS调用WCF系列-----实现JSON传递第一节:ExtJS调用WCF系列-----实现JSON传递     success: function(response, options) 
第一节:ExtJS调用WCF系列-----实现JSON传递{ Ext.get('GetByNum-p').update(response.responseText);}
第一节:ExtJS调用WCF系列-----实现JSON传递     failure: onFailure 
第一节:ExtJS调用WCF系列-----实现JSON传递     }
); 
第一节:ExtJS调用WCF系列-----实现JSON传递     }
);
第一节:ExtJS调用WCF系列-----实现JSON传递    
</script>
第一节:ExtJS调用WCF系列-----实现JSON传递
</head>
第一节:ExtJS调用WCF系列-----实现JSON传递
<body>
第一节:ExtJS调用WCF系列-----实现JSON传递    
<form id="form1" runat="server">
第一节:ExtJS调用WCF系列-----实现JSON传递     
<div>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<h3>
第一节:ExtJS调用WCF系列-----实现JSON传递            Create:
</h3>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<p id="create-p">
第一节:ExtJS调用WCF系列-----实现JSON传递        
</p>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<h3>
第一节:ExtJS调用WCF系列-----实现JSON传递            Get:
</h3>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<p id="get-p">
第一节:ExtJS调用WCF系列-----实现JSON传递        
</p>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<h3>
第一节:ExtJS调用WCF系列-----实现JSON传递            GetAll:
</h3>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<p id="getall-p">
第一节:ExtJS调用WCF系列-----实现JSON传递        
</p>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<h3>
第一节:ExtJS调用WCF系列-----实现JSON传递            GetByNum:
</h3>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<p id="GetByNum-p">
第一节:ExtJS调用WCF系列-----实现JSON传递        
</p>
第一节:ExtJS调用WCF系列-----实现JSON传递        
<p id="errors">
第一节:ExtJS调用WCF系列-----实现JSON传递        
</p>
第一节:ExtJS调用WCF系列-----实现JSON传递    
</div>
第一节:ExtJS调用WCF系列-----实现JSON传递    
</form>
第一节:ExtJS调用WCF系列-----实现JSON传递
</body>
第一节:ExtJS调用WCF系列-----实现JSON传递
</html>
第一节:ExtJS调用WCF系列-----实现JSON传递

最终的运行效果:
第一节:ExtJS调用WCF系列-----实现JSON传递
源代码下载在这里 

转载于:https://www.cnblogs.com/xiaozhuang/archive/2007/12/07/987092.html