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
Ïà¹ØÎĵµ£º
ÈçºÎÔÚ¿Í»§¶ËÖ±½Óµ÷ÓÃWebServiceÖеķ½·¨£¿
ÕâÀï½áºÏ¾Ñé×Ô¼ºÐ´Ò»Ð´
1.Ê×ÏÈн¨Ò»¸ö ASP.NET AJAX-Enabled Web Site,ÕâÑùϵͳΪÎÒÃÇ×Ô¶¯ÅäÖúÃÁË»·¾³£¬ÕâÖ÷ÒªÌåÏÖÔÚWeb.configÕâ¸öÎļþÉÏ£¬Èç¹ûÒÑÓÐÍøÕ¾²»ÊÇASP.NET AJAX-Enabled Web SiteÒ²¿ÉÒÔ¶ÔÕÕÐÞ¸ÄÏÂWeb.config£¬Ò²¿ÉÒÔ´ïµ½ÏàͬµÄЧ¹û¡£
2.н¨Ò»¸öweb·þÎñ£¬WebSer ......
asp.net ajaxѧϰ±Ê¼Ç
Ò»¡¢ µÇÌÃÈëÊÒ——»ù±¾¸ÅÄî
http://blog.csdn.net/soldierluo/archive/2009/11/18/4830758.aspx
¶þ¡¢ СÊÔÉíÊÖ——µÚÒ»¸öAjax³ÌÐò
http://bl ......
jQuery µ×²ã AJAX ʵÏÖ¡£¼òµ¥Ò×Óõĸ߲ãʵÏÖ¼û $.get, $.post µÈ¡£$.ajax() ·µ»ØÆä´´½¨µÄ XMLHttpRequest ¶ÔÏó¡£´ó¶àÊýÇé¿öÏÂÄãÎÞÐèÖ±½Ó²Ù×÷¸Ã¶ÔÏ󣬵«ÌØÊâÇé¿öÏ¿ÉÓÃÓÚÊÖ¶¯ÖÕÖ¹ÇëÇó¡£
×¢Ò⣺ Èç¹ûÄãÖ¸¶¨ÁË dataType Ñ¡ÏÇëÈ·±£·þÎñÆ÷·µ»ØÕýÈ·µÄ MIME ÐÅÏ¢£¬(Èç xml ·µ»Ø "text/xml")¡£´íÎóµÄ MIME ÀàÐÍ¿ÉÄܵ¼Ö²»¿ÉÔ¤Ö ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/ ......