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

推荐订阅源

P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
博客园_首页
宝玉的分享
宝玉的分享
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
T
Tailwind CSS Blog
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
月光博客
月光博客
罗磊的独立博客
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 聂微东
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
阮一峰的网络日志
阮一峰的网络日志
I
InfoQ
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Scott Helme
Scott Helme
B
Blog
M
MIT News - Artificial intelligence
K
Kaspersky official blog
H
Help Net Security
V
Vulnerabilities – Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】
L
Lohrmann on Cybersecurity
P
Privacy & Cybersecurity Law Blog
Project Zero
Project Zero
The Hacker News
The Hacker News
B
Blog RSS Feed
T
Tor Project blog

博客园 - 柠茶

asp.net webapi 参数绑定总结 asp.net webapi 参数绑定总结 javascript引用类型 javascript变量,作用域和内存问题 javascript基本概念 javascript中所谓的“坑”收录 反射体验(转) 什么是Emit,什么是反射,二者区别到底是什么?(转) 关于可空类型 学习IIS & MVC的运行原理 (转) MVC-READ5(asp.net web from PK asp.net MVC) MVC-READ4 MVC-READ3(视图引擎主要类关系图) MVC-READ2 MVC-READ1 @@ERROR和@@ROWCOUNT的用法 异常以及异常处理框架探析(转) .Net深入学习序列化和反序列化 (转) 可扩展对象模式(转)
JS调用webservice的两种方式
柠茶 · 2014-11-27 · via 博客园 - 柠茶

协议肯定是使用http协议,因为soap协议本身也是基于http协议。期中第二种方式:只有webservice3.5以后版本才可以成功

第一种方式:构造soap格式的body,注意加粗的黄色标识,比如:

createXMLHttpRequest();
    var data;
    data = '<?xml version="1.0" encoding="utf-8"?>';
    data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
    data = data + "<soap:Header>"
    data = data + '<UserSoapHeader xmlns="http://tempuri.org/">'
    data = data + "<UserName>admin</UserName>"
    data = data + "<Pwd>faaaa</Pwd>"
    data = data + "</UserSoapHeader>"
    data = data + "</soap:Header>"
    
    
    data = data + '<soap:Body>';
    data = data + '<'+method+' xmlns="'+_Namespace+'">';
    for(var i=0;i<variable.length;i++)
    {
      data = data + '<'+variable[i]+'>'+value[i]+'</'+variable[i]+'>';
    }
    data = data + '</'+method+'>';
    data = data + '</soap:Body>';
    data = data + '</soap:Envelope>';
      
    xmlhttp.onreadystatechange=handleStateChange;
    xmlhttp.Open("POST",url, true);
    xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
    xmlhttp.SetRequestHeader ("Content-Length",getlen(data));
    xmlhttp.SetRequestHeader ("SOAPAction",_Namespace+method);
    xmlhttp.Send(data);
   

第二种方式(我没使用过,想着不会成功):构造json格式的body,比如:

createXMLHttpRequest();  

urlhttp://....../a.asmx/webservice方法名

body使用json数据格式

xmlhttp.SetRequestHeader ("Content-Type","application/json; charset=utf-8");
    xmlhttp.SetRequestHeader ("Content-Length",getlen(body));