首先定義SOAP數據,然后創建HTTP對象,然后使用POST提交,獲取狀態碼為200,就說明調用成功,再進行下一步操作……
看一下具體實現的代碼吧
01 | <!--#Include virtual= "/Include/json.min.asp" --> |
02 | <% |
03 | Dim strxml |
04 | Dim str |
05 |
06 | '定義soap消息 |
07 | strxml = "<?xml version='1.0' encoding='utf-8'?>" |
08 | strxml = strxml & "<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/'>" |
09 | strxml = strxml & "<soap:Body> " |
10 | strxml = strxml & "<GetCategories xmlns='http://tempuri.org/'>" |
11 | strxml = strxml & "<reqcode>30000001</reqcode>" '參數1 |
12 | strxml = strxml & "<sign>ssssss</sign>" '參數2 |
13 | strxml = strxml & "</GetCategories>" |
14 | strxml = strxml & "</soap:Body>" |
15 | strxml = strxml & "</soap:Envelope>" |
16 |
17 | Set h = createobject( "Microsoft.XMLHTTP" ) |
18 | '向指定的URL發送Post消息 |
19 | h.open "POST" , "http://www.domain.com/WebService.asmx" , False |
20 | h.setRequestHeader "Content-Type" , "text/xml; charset=utf-8" |
21 | h.setRequestHeader "Content-Length" ,LEN(strxml) |
22 | h.setRequestHeader "SOAPAction" , "http://tempuri.org/GetCategories" |
23 | h.send (strxml) |
24 |
25 | '顯示返回的XML信息 |
26 |
27 | If h.Status = 200 Then |
28 | Set xmlDOC = server.CreateObject( "MSXML.DOMDocument" ) |
29 | xmlDOC.load(h.responseXML) |
30 | jsonText = xmlDOC.childNodes(1).Text |
31 | |
32 | '轉換成JSON,調用json.min.asp |
33 | Set categories = JSON.parse(jsonText) |
34 | |
35 | for i = 0 to categories.Length -1 |
36 | Response.Write( CStr (categories.get(i).CategoryName)) '屬性 |
37 | for j = 0 to categories.get(i).Labels.Length - 1 '集合 |
38 | Response.Write( CStr (categories.get(i).Labels.get(j).LabelName)) |
39 | next |
40 | next |
41 | <pre name= "code" class= "vb" ><script language= "javascript" runat= "Server" > |
42 | if(!Array.prototype.get){Array.prototype.get=function(prop){return this[prop];}} "use strict" ;if(!this.JSON){JSON={};} |
43 | (function(){function f(n){return n<10? '0'+n:n;} |
44 | if(typeof Date .prototype.toJSON!== 'function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ |
45 | f(this.getUTCMonth()+1)+ '-'+ |
46 | f(this.getUTCDate())+ 'T'+ |
47 | f(this.getUTCHours())+ ':'+ |
48 | f(this.getUTCMinutes())+ ':'+ |
49 | f(this.getUTCSeconds())+ 'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} |
50 | var cx=/[\?\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,escapable=/[\\\ "\x00-\x1f\x7f-\x9f\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','" ':'\\ "','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'" '+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+' "':'" '+string+'"';} |
51 | function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value=== 'object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} |
52 | if(typeof rep=== 'function'){value=rep.call(holder,key,value);} |
53 | switch(typeof value){case 'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} |
54 | gap+=indent;partial=[];if( Object .prototype.toString.apply(value)=== '[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';} |
55 | v=partial.length===0? '[]':gap?'[\n'+gap+ |
56 | partial.join( ',\n'+gap)+'\n'+ |
57 | mind+ ']':'['+partial.join(',')+']';gap=mind;return v;} |
58 | if(rep&&typeof rep=== 'object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}} |
59 | v=partial.length===0? '{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+ |
60 | mind+ '}':'{'+partial.join(',')+'}';gap=mind;return v;}} |
61 | if(typeof JSON.stringify!== 'function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;} |
62 | rep=replacer;if(replacer&&typeof replacer!== 'function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');} |
63 | return str( '',{'':value});};} |
64 | if(typeof JSON.parse!== 'function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} |
65 | return reviver.call(holder,key,value);} |
66 | cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return '\\u'+ |
67 | ( '0000'+a.charCodeAt(0).toString(16)).slice(-4);});} |
68 | if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:[ "\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/" [^ "\\\n\r]*" |true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;} |
69 | throw new SyntaxError( 'JSON.parse');};}}()); |
70 | </script> |
71 | Set xmlDOC = nothingElse Response.Write h.Status & " " Response.Write h.StatusTextEnd if%> |
01 | <script language= "javascript" runat= "Server" > |
02 | if(!Array.prototype.get){Array.prototype.get=function(prop){return this[prop];}} "use strict" ;if(!this.JSON){JSON={};} |
03 | (function(){function f(n){return n<10? '0'+n:n;} |
04 | if(typeof Date .prototype.toJSON!== 'function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ |
05 | f(this.getUTCMonth()+1)+ '-'+ |
06 | f(this.getUTCDate())+ 'T'+ |
07 | f(this.getUTCHours())+ ':'+ |
08 | f(this.getUTCMinutes())+ ':'+ |
09 | f(this.getUTCSeconds())+ 'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} |
10 | var cx=/[\?\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,escapable=/[\\\ "\x00-\x1f\x7f-\x9f\?\?-\?\?\?\?\?-\?\?-\?\?-\?\?\?-\?]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','" ':'\\ "','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'" '+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+' "':'" '+string+'"';} |
11 | function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value=== 'object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} |
12 | if(typeof rep=== 'function'){value=rep.call(holder,key,value);} |
13 | switch(typeof value){case 'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} |
14 | gap+=indent;partial=[];if( Object .prototype.toString.apply(value)=== '[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';} |
15 | v=partial.length===0? '[]':gap?'[\n'+gap+ |
16 | partial.join( ',\n'+gap)+'\n'+ |
17 | mind+ ']':'['+partial.join(',')+']';gap=mind;return v;} |
18 | if(rep&&typeof rep=== 'object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}} |
19 | v=partial.length===0? '{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+ |
20 | mind+ '}':'{'+partial.join(',')+'}';gap=mind;return v;}} |
21 | if(typeof JSON.stringify!== 'function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;} |
22 | rep=replacer;if(replacer&&typeof replacer!== 'function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');} |
23 | return str( '',{'':value});};} |
24 | if(typeof JSON.parse!== 'function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} |
25 | return reviver.call(holder,key,value);} |
26 | cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return '\\u'+ |
27 | ( '0000'+a.charCodeAt(0).toString(16)).slice(-4);});} |
28 | if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:[ "\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/" [^ "\\\n\r]*" |true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;} |
29 | throw new SyntaxError( 'JSON.parse');};}}()); |
30 | </script> |