惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - Blackie

碰到shiro反序列化漏洞,大家都是怎么解决的 由于 ASP.NET 进程标识对全局程序集缓存没有读权限,因此未能执行请求。错误: 0x80131902 vs 2005 thread 无法调试 windows 2003 不同网段 无法 文件共享 VSS设置 添加COM类型库ACTIVEX接口 - Blackie - 博客园 windows media play javascript 全屏 单击事件 今天把HP6520S笔记本给拆解了 如何引用 System.Runtime.Serialization.Json; FLASH CS4 制作渐变 动画 有补间动画 传统补间 json2string json格式到string的转换,调试有时候可以用到 asp.net ajax 客户端框架未能加载 sys 未定义 - Blackie WCF 返回json的时间格式的转换 - Blackie - 博客园 WCF IIS 用户名消息安全 可能碰到的问题 - Blackie 今天发布的一个程序一直提示Microsoft.mshtml的强名称验证失败 在ASP.NET 中调用RSACryptoServiceProvider失败,提示未找到文件 显示listview的行号 - Blackie - 博客园 AxWebBrowser,WebBrowser 分页SQL语句的性能比较 remoting作成windows服务后一直无法读取配置文件,可能的原因之一。
jquery 跨域调用wcf 返回json 碰到的一些问题
Blackie · 2009-04-27 · via 博客园 - Blackie

走到这里的时候,发现网络上能学习的资源或是比较适合自己项目的文章越来越少了,也在这里停留了比较长的时间

在做跨域的过程中,感觉http://localhost:9090/域与http://localhost/这是属于同样的域,或是说这样的试验没法证明是跨域

试验的过程中,建议先测试一些简单的例子,比如在服务器先放一些ASP页面直接能返回内容的,且不存在逻辑过程的,这样可以更直观的发现问题

Code

以上是我放在asp页面的内容,当然更建议您再简单些,比如<%Response.Write(Request("callback"))%>('abcdf'),jsonp的回调函数。在这里如果不是很了解json数据格式,及调用json数据的方式的朋友需要知道。

callback(json数据)这里的json数据不要用引号。

然后把该页面放在服务端,

本地调用。

我目前是使用jquery,主要是觉得他的轻巧。当然如果您的项目在内部运行,或整体加载速度等不是问题,且需要较好的UI,可以考虑EXTJS

在htm页面

第一,引用jquery的脚本文件

第二,html <button id="btnTest"> BtnTest</button>

有以下脚本

r参数是一个随机值,防止缓存的,其实跟踪客户端发出的数据会发现jquery会自动给该请求加上一个“_” 的参数,值是一个随机变量应该也是解决缓存的,

callback=?和下面的dataType:"json",如果dataType:"jsonp",那么就不需要加callback=?这个参数了,这个可以在服务端调试的时候发现到,

processData:false,默认是true,当我们的发送参数是传统的格式的时候,设置为false

ShowAv是回调函数,如果我们在服务端调试,在上面我们有看到服务端需要接收callback的参数,调试的时候会发现是一个类似jsonxxxxxx的值,在jquery里有明确的说明这个值即代表本文的ShowAv函数,

这样再认真查看服务端的代码,就会明白,服务端的代码实际上就是ShowAv('abcdf'),就是这样,也就是说,以下的脚本最终实现的一个目的与我们调用一个远程脚本文件(文件的内容是ShowAv('abcdf'))是一样的效果。这就是jsonp的原理所在。(有人说jsonp早就存在就是这个意思。)

Code

以上的ShowAv函数,您可以添加任意您想要的测试脚本。

 以上内容主要是针对初学者,进行跨域的测试,以及json数据的测试。

下面主要涉及的内容是wcf数据的提供。

这里提到的方法主要是针对跨域的WCF服务,如果没有跨域的WCF服务不需要如果此复杂。

在以上测试成功后,可以开始连接到我们提供WCF服务。

以下提供的服务方法,是支持http的get方法,返回的是Stream格式,AirFlights是这个服务原来返回的一个实体

被注释的部分是我曾尝试直接让WCF返回字符串格式,但在调试的时候会发现如果返回设置为json格式,整个字符串会被引号起来,下面的那种方法是借鉴了http://www.cnblogs.com/jillzhang/archive/2009/03/13/1245458.html

[WebGet(ResponseFormat = WebMessageFormat.Json,  BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        
public Stream CmdAVAjaxP(string cmdString, string callBack)
        {
            
if (String.IsNullOrEmpty(cmdString))
            {
                
return null;
            }
            AirFlights air 
= CmdAVSearch(cmdString);
            //JsonQueryStringConverter jqsc 
= new JsonQueryStringConverter();
            //
string strRe = String.Format("{1}({0})", jqsc.ConvertValueToString(air, typeof(AirFlights)), callBack);
            
//string strRe = jqsc.ConvertValueToString(air, typeof(AirFlights));
            
//return strRe;

            System.Runtime.Serialization.Json.DataContractJsonSerializer formater 
= new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(AirFlights));
            MemoryStream ms 
= new MemoryStream();
            formater.WriteObject(ms, air);
            ms.Position 
= 0;
            StreamReader sr 
= new StreamReader(ms);
            
string objContent = sr.ReadToEnd();
            
string returnStr = callBack + "(" + objContent + ")";
            sr.Close();
            ms 
= new MemoryStream();
            StreamWriter sw 
= new StreamWriter(ms);
            sw.AutoFlush 
= true;
            sw.Write(returnStr);
            ms.Position 
= 0;
            WebOperationContext.Current.OutgoingResponse.ContentType 
= "text/plain";
            
return ms;
        }

这样基本上就OK了。