Cross Domain AJAX Enabled WCF Service
Background For the basic of how to create an AJAX enabled WCF service, please refer to MSDN: http://msdn.microsoft.com/en-us/library/bb924552.aspx. For the basic of JSONP, please refer to: http://en.wikipedia.org/wiki/JSON#JSONP. This article introduce how to make AJAX enabled WCF service support cross-domain request. In the WCF & WF samples provided by Microsoft, there is already a “custom binding extension” implementation for JSONP support. But there is some limitation, the biggest limitation is it could not support both JSON & JSONP protocol for one AJAX enabled WCF service URL, and it requires each endpoint you want to support JSONP protocol be configured with the specific custom JSONP binding extension which increased configuration complexity & cost. Here I introduce a more general “custom Http Module” implementation for cross-domain calling AJAX enabled WCF services. At the beginning, firstly, please realize WCF does not support custom Http Modules by default, which means, by default, a WCF service request, even a webHttpBinding AJAX enabled WCF service request, doesn’t go through any custom Http Modules. To enable it, you need to set the aspNetCompatibilityEnabled property of serviceHostingEnvironment element to true like below:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
...
</system.serviceModel>And to enable a WCF service support custom Http Module, you also need to mark the AspNetCompatibilityRequirementsAttribute on the service contract like below: [ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class TestAjaxClientService
{
...
}JSONPModule Since with the aspNetCompatibilityEnabled property set to true, an Http WCF service request goes through custom Http Modules, it is
相关文档:
在构造url是用javascript自带的encodeURIComponent方法将参数进行编码,下面是我的代码
var url = "handel.jsp?name="+encodeURIComponent(document.form1.name.value);
httpRequest = createHttpRequest();
httpReque ......
如何在客户端直接调用WebService中的方法?
这里结合经验自己写一写
1.首先新建一个 ASP.NET AJAX-Enabled Web Site,这样系统为我们自动配置好了环境,这主要体现在Web.config这个文件上,如果已有网站不是ASP.NET AJAX-Enabled Web Site也可以对照修改下Web.config,也可以达到相同的效果。
2.新建一个web服务,WebSer ......
1. Accordion
【功能概述】Accordion可以让你设计多个panel 并且一次只显示一个Panel .在页面上的显示效果就像是使用了多个CollapsiblePanels只不过每一次只展开其中一个 CollapsiblePanel.Accordion控件内部包含了若干个AccordionPane,每一个AccordionPane的 template里包括了对其Header和Content的定义。我们可以在后台 ......
前后端的交互是整个框架的中心,我希望从流的角度来设计AJAX的交互
AJAX的设计将横贯前后端
前端是主动
后端是被动
整体考虑的话 前后端使用一个统一的接口进行AJAX交互
后端 用一个唯一的URL来处理 AJAX请求
接口名称 处理接口:[http://域名/mvc.ajax] 封装所有的AJAX请求的预处理
......
var xmlhttp;
function verify()
{
//2.创建XmlHttpRequest对象
//这是XmlHttpRequest对象五步中使用最复杂的一步
//需要针对IE和其他类型的浏览器建立这个对象的不同方式写不同的代码
if(window.XMLHttpRequest)
{
......