// http://lostinet.d2g.com/Lostinet-Publish/JScriptSoapClient/
body
{
color:black;background-color:white;
}
span.kw
{
color:blue;
}
span.string
{
background-color:#EEEEEE;
color:steelblue;
}
span.lr
{
color:maroon;
}
/****************************************************************\
<lostinet:source xmlns:lostinet="http://www.lostinet.com/lostinet-source/">
<lostinet:source-info>
<lostinet:name>JScriptSoapClient For .Net</lostinet:name>
<lostinet:version>0.203</lostinet:version>
<lostinet:description>SoapClient的JScript实现,Beta版</lostinet:description>
</lostinet:source-info>
<lostinet:author-info>
<lostinet:name>Lostinet</lostinet:name>
<lostinet:email>lostinet@21cn.com;lostinet@chongjian.com;</lostinet:email>
<lostinet:homepage>http://www.lostinet.com/</lostinet:homepage>
</lostinet:author-info>
<lostinet:copyright-info>
<lostinet:copyright>版权声明:这个软件可以随意发布。也可以根据具体情况进行优化修改。但是请保留作者的相关信息。</lostinet:copyright>
</lostinet:copyright-info>
</lostinet:source>
\****************************************************************/
/*
JScriptSoapClient For .Net
作者:迷失网络[Lostinet]
为你的WebService提供简单易用的调用方案
暂时只支持 string,int,float,double,boolean 的传输
使用方法:
var wsdl=new JScriptSoapClient("http://host.com/webservice.asmx?WSDL");
var ws=wsdl.CreateWebService("webservicename");
var res=ws.MethodName(arg1,arg2);
alert(res);
alert(res.Length);
alert(res.Item(0)+res.Item(1).Value+res.Item(2).Type);
*/
@cc_on
@set @debug=true
/****************************************************************\
++++JScript+Operation+++JScript+Operation+++JScript+Operation+++++
\****************************************************************/
function GetUndefined(){}
function IsUndefined(unknown){
return typeof(unknown)=="undefined";
}
function typeOf(unknown){
return typeof(unknown);
}
function valueOf(unknown){
if(IsUndefined(unknown))return GetUndefined();
try{
return unknown.valueOf();
}catch(x){}
return unknown;
}
function toString(unknown){
if(IsUndefined(unknown))return "";
if(unknown===null)return "";
try{
return unknown.toString();
}catch(x){}
return unknown+"";
}
function IsEqual(unknown1,unknown2){
return unknown1==unknown2;
}
function IsIdentical(unknown1,unknown2){
return unknown1===unknown2;
}
function Is(unknown){
return unknown?true:false;
}
function Not(unknown){
return unknown?false:true;
}
function IsNull(unknown){
switch(typeOf(unknown))
{
case "undefined":return true;
case "string":return unknown=="";
case "number":return unknown==0;
case "object":return unknown==null;
case "function":return false;
case "boolean":return unknown?false:true;
default:return unknown?false:true;
}
}
function IsBoolean(unknown){
return typeOf(unknown)=="boolean";
}
function IsNumber(unknown){
return typeOf(unknown)=="number";
}
function IsString(unknown){
return typeOf(unknown)=="string";
}
function IsFunction(unknown){
return typeOf(unknown)=="function";
}
function IsObject(unknown){
return typeOf(unknown)=="object";
}
function IsJScriptObject(unknown)
{
if(false==IsObject(unknown)&&false==IsFunction(unknown))return false;
try{
return IsFunction(unknown.constructor);
}catch(x){
}
return false;
}
function VarValueOf(unknown){
var arr=new Array();
var unknown2=unknown;
while(unknown=valueOf(unknown))
{
if(unknown2===unknown)return unknown;
arr[arr.length]=unknown2;
for(var i=0;i<arr.length;i++)
{
if(arr[i]===unknown)ThrowError("VarValueOf()检测到的valueOf环");
}
unknown2=unknown;
}
}
function VarToString(unknown){
return toString(VarValueOf(unknown));
}
function VarTypeOf(unknown){
return typeOf(VarValueOf(unknown));
}
function VarIsEqual(unknown1,unknown2){
return IsEqual(VarValueOf(unknown1),VarValueOf(unknown2));
}
function VarIsIdentical(unknown1,unknown2){
return IsIdentical(VarValueOf(unknown1),VarValueOf(unknown2));
}
function VarIsNull(unknown){
return IsNull(VarValueOf(unknown));
}
function VarIs(unknown){
return VarValueOf(unknown)?true:false;
}
function VarNot(unknown){
return VarValueOf(unknown)?false:true;
}
//下面的判断根据VarValueOf来进行。
//对变量进行属性操作前不要使用这些判断
//保留应用:对于以后的Delegate的扩充
function VarIsBoolean(unknown){
return VarTypeOf(unknown)=="boolean";
}
function VarIsNumber(unknown){
return VarTypeOf(unknown)=="number";
}
function VarIsString(unknown){
return VarTypeOf(unknown)=="string";
}
function VarIsFunction(unknown){
return VarTypeOf(unknown)=="function";
}
function VarIsObject(unknown){
return VarTypeOf(unknown)=="object";
}
/****************************************************************\
----JScript-Operation---JScript-Operation---JScript-Operation-----
\****************************************************************/
function IsObjectPPT(name)
{
ASSERT(IsString(name),"IsObjectPPT()参数错误");
var arr=new Array("constructor","hasOwnProperty","instanceof","isPrototypeOf","length","prototype","propertyIsEnumeramble","toString","valueOf");
for(var i=0;i<arr.length;i++)
if(arr[i]==name)return true;
return false;
}
function ThrowError(msg){
throw(new Error(-1,msg));
}
@if(@debug)
function ASSERT(mustbetrue,msg){
if(mustbetrue)return;
msg?null:(msg="下面函数发生未指定错误:\m"+fs().caller);
ThrowError("ASSERT - 发生错误:\n"+msg);
}
function
BREAKPOINT(msg){
msg?null:(msg=fs().caller);
msg="BREAKPOINT,是否抛出异常?:\n"+msg;
try{
if(confirm(msg)==false)return;
}catch(x){
}
ThrowError("BREAKPOINT抛出异常");
}
function ALERT(msg){
try{
window.alert(msg);
return;
}catch(x){}
try{
WScript.Echo(msg);
return;
}catch(x){}
}
@else
function ASSERT(mustbetrue,msg){}
function
BREAKPOINT(msg){}
function ALERT(msg){}
@end
function fs(){return fs.caller}
function IsCalledByNew(_This){
try{
if(_This&&_This.constructor&&fs().caller==_This.constructor)
return true;
}catch(x){}
return false;
}
//var1,var2,明确参数
function Delegate(var1,var2)
{
if(IsCalledByNew(this))ThrowError("new Delegate()是不合法的调用方式");
if(IsUndefined(var1))ThrowError("Delegate()参数无效");
if(IsUndefined(var2)){
ASSERT(IsFunction(var1),"Delegate的参数非function");
return Delegate_Function(var1);
}
ASSERT(IsFunction(var1)||IsObject(var1),"Delegate的参数非object");
if(IsString(var2)){
ASSERT(IsObject(var1[var2])||IsFunction(var1[var2]),"Delegate的参数不是方法");
return Delegate_Method(var1,var2);
}
else{
ASSERT(IsJScriptObject(var1),"Delegate的参数非JScriptObject");
ASSERT(IsFunction(var2),"Delegate的参数非function");
return Delegate_VirtualMethod(var1,var2);
}
function Delegate_Function(func)
{
function Function(){
if(IsNull(Function._Function))return;
var arr=new Array();
for(i=0;i<Function.arguments.length;i++)
arr[arr.length]="Function.arguments["+i+"]";
for(;i<Function._Arguments.length;i++)
arr[arr.length]="Function._Arguments["+i+"]";
var strArguments=arr.join(",");
var strEval="Function._Function("+strArguments+")"
strEval="var f=(function(){return "+strEval+"});f.Delegate=Function;f()";
return eval(strEval);
}
function Function.valueOf(){return Function();}
function Function.toString(){return Function();}
function Function.PreInvoke(){
Function._Arguments=new Array();
Function.SetArguments(Function.PreInvoke.arguments);
return Function;
}
function Function.SetArguments(args){
for(var i=0;i<args.length;i++)
Function._Arguments[i]=args[i];
return Function;
}
function Function.Detach(){
Function._Function=null;
Function._Arguments=null;
}
Function._Function=func;
Function._Arguments=new Array();
return Function;
}
function Delegate_Method(obj,name)
{
function Function(){
if(IsNull(Function._Object))return;
var arr=new Array();
for(i=0;i<Function.arguments.length;i++)
arr[arr.length]="Function.arguments["+i+"]";
for(;i<Function._Arguments.length;i++)
arr[arr.length]="Function._Arguments["+i+"]";
var strArguments=arr.join(",");
var strEval="Function._Object."+Function._Name+"("+strArguments+")";
strEval="var f=(function(){return "+strEval+"});f.Delegate=Function;f()";
return eval(strEval);
}
function Function.valueOf(){return Function();}
function Function.toString(){return Function();}
function Function.PreInvoke(){
Function._Arguments=new Array();
Function.SetArguments(Function.PreInvoke.arguments);
return Function;
}
function Function.SetArguments(args){
for(var i=0;i<args.length;i++)
Function._Arguments[i]=args[i];
return Function;
}
function Function.Detach(){
Function._Object=null;
Function._Name="";
Function._Arguments=null;
}
Function._Object=obj;
Function._Name=name;
Function._Arguments=new Array();
return Function;
}
function Delegate_VirtualMethod(obj,func)
{
function Function(){
if(IsNull(Function._Object))return;
var arr=new Array();
for(i=0;i<Function.arguments.length;i++)
arr[arr.length]="Function.arguments["+i+"]";
for(;i<Function._Arguments.length;i++)
arr[arr.length]="Function._Arguments["+i+"]";
var strArguments=arr.join(",");
var ppt="DelegateVirtualMethod"+new Date().getTime()+"_"+Math.floor(Math.random()*1000000);
Function._Object[ppt]=func;
var res,error;
var strEval="Function._Object."+ppt+"("+strArguments+")";
strEval="var f=(function(){return "+strEval+"});f.Delegate=Function;f()";
try{
res=eval(strEval);
}catch(x){
error=x;
}
if(!IsNull(Function._Object))delete Function._Object[ppt];
if(error)throw(error);
return res;
}
function Function.valueOf(){return Function();}
function Function.toString(){return Function();}
function Function.PreInvoke(){
Function._Arguments=new Array();
Function.SetArguments(Function.PreInvoke.arguments);
return Function;
}
function Function.SetArguments(args){
for(var i=0;i<args.length;i++)
Function._Arguments[i]=args[i];
return Function;
}
function Function.Detach(){
Function._Object=null;
Function._Function=null;
Function._Arguments=null;
}
Function._Object=obj;
Function._Function=func;
Function._Arguments=new Array();
return Function;
}
}
function Delegate.QueryDelegate()
{//小心objDelegate.valueOf()递归
return fs().caller.caller.Delegate;
}
function JScriptSoapClient(wsdlurl,username,password,wsdlxml)
{
function GetNodeName(prefix,baseName){
ASSERT(IsString(baseName)&&!IsNull(baseName),"GetNodeName()参数错误");
if(""!=prefix)return prefix+":"+baseName;
return baseName;
}
function TagNameToPrefix(tagName){
ASSERT(typeof(tagName)=="string","TagNameToBaseName():"+tagName);
if(tagName.indexOf(":")==-1)return "";
return tagName.substr(0,tagName.indexOf(":"));
}
function TagNameToBaseName(tagName){
ASSERT(typeof(tagName)=="string","TagNameToBaseName():"+tagName);
if(tagName.indexOf(":")==-1)return tagName;
return tagName.substring(tagName.indexOf(":")+1,tagName.length);
}
function CreateDefaultCollection()
{
return FunctionSpace();
function FunctionSpace()
{
var _Length=0;
var _Coll=new Object();
function Collection(index)
{
return Collection.Item(index);
}
function Collection.valueOf(){
if(_Length==0)return GetUndefined();
return VarValueOf(Collection.Item(0));
}
function Collection.toString(){
return VarToString(Collection.valueOf());
}
function Collection.Length(){return _Length;}
function Collection.Length.valueOf(){
return Collection.Length();
}
function Collection.Length.toString(){
return Collection.Length();
}
function Collection.Item(index){
ASSERT(index<_Length||IsNull(_Coll[index])==false,"找不到Item:"+index);
if(!IsNumber(index))return _Coll[index];
var pos=0;
for(var ppt in _Coll){
if(pos==index)return _Coll[ppt];
pos++;
}
ASSERT(0,"CreateDefaultCollection::Collection.Item : 不能到达");
}
function Collection._add(obj){
ASSERT(IsJScriptObject(obj)&&IsString(obj.Name),"CreateDefaultCollection::Collection._add : 参数错误");
ASSERT(obj.Name!=parseInt(obj.Name),"CreateDefaultCollection::Collection._add : obj.Name 不能为数字");
if(IsJScriptObject(_Coll[obj.Name]))return true;
_Coll[obj.Name]=obj;
_Length++;
return true;
}
return Collection;
}
}
ASSERT( (!IsNull(wsdlxml)) || (!IsNull(wsdlurl)) ,"JScriptSoapClient参数错误");
username?null:username=GetUndefined();
password?null:password=GetUndefined();
if(!IsCalledByNew(this))
return new (fs())(wsdlurl,username,password,wsdlxml);
return CreateSoapClient();
function CreateSoapClient()
{
var CurrentSoapClient=new Object();
CurrentSoapClient.CollWebServiceInfo=CreateDefaultCollection();
CurrentSoapClient.URL=wsdlurl;
CurrentSoapClient.UserName=username;
CurrentSoapClient.Password=password;
var xdWSDL=null;
while(1)
{
try{
if(!IsNull(wsdlxml))
{
xdWSDL=new ActiveXObject("Microsoft.XMLDOM");
xdWSDL.loadXML(wsdlxml);
if(xdWSDL.parseError.errorCode)
ThrowError(xdWSDL.parseError.reason);
break;
}
xdWSDL=(function(){
var xh=new ActiveXObject("Microsoft.XMLHTTP");
xh.open("GET",wsdlurl,false,username,password);
xh.send();
var xd=xh.responseXML;
if(xd.parseError.errorCode)
ThrowError(xd.parseError.reason);
if(IsNull(xd.documentElement))
ThrowError("不能取得"+wsdlurl+"\n可能是没有足够的权限");
return xd;
})();
break;
}catch(x){
ThrowError(
"不能加载WSDL:\n"
+wsdlurl+"\n\n详细的信息:\n"
+(x.message?x.message:x.description)
);
}
}
CurrentSoapClient.XMLNS=xdWSDL.documentElement.getAttribute("targetNamespace");
var collNs={
target :CurrentSoapClient.XMLNS,
wsdl :"http://schemas.xmlsoap.org/wsdl/",
soap :"http://schemas.xmlsoap.org/wsdl/soap/",
soaphttp :"http://schemas.xmlsoap.org/soap/http",
soapenc :"http://schemas.xmlsoap.org/soap/encoding/",
xsi :"http://www.w3.org/2001/XMLSchema-instance",
xsd :"http://www.w3.org/2001/XMLSchema"
};
var collPf=new Object();
for(var i in collNs){
var pf=(function(de,ns){
var nsAttr=de.attributes;
for(var i=0;i<nsAttr.length;i++){
var nAttr=nsAttr.item(i);
if(nAttr.prefix=="xmlns"&&nAttr.nodeValue==ns)
return nAttr.baseName;
if(nAttr.prefix==""&&nAttr.baseName=="xmlns"&&nAttr.nodeValue==ns)
return "";
}
return null;
})(xdWSDL.documentElement,collNs[i]);
if(pf===null)continue;
collPf[i]=pf;
}
var xdrootpath="//"+GetNodeName(collPf["wsdl"],"definitions")+"/";
var nsService=xdWSDL.selectNodes(xdrootpath+GetNodeName(collPf["wsdl"],"service"));
ASSERT(nsService.length>0,"WSDL中不包含WebService的描述");
var nService;
for(var i=0;i<nsService.length;i++)
{
nService=nsService.item(i);
CurrentSoapClient.CollWebServiceInfo._add(CreateWebServiceInfo());
}
delete nService;delete nsService;delete i;delete xdrootpath;
@if(@debug==false)
delete xdWSDL;
@end
CurrentSoapClient.CreateWebService=(function(name){
ASSERT(IsString(name),"CreateWebService()参数无效");
var wsi=CurrentSoapClient.CollWebServiceInfo.Item(name);
if(IsNull(wsi))ThrowError("找不到WebService:"+name);
return wsi.Create();
});
return CurrentSoapClient;
function CreateWebServiceInfo()
{
//stack var CurrentWebServiceInfo
var CurrentWebServiceInfo=new Object();
CurrentWebServiceInfo.CollWebMethodInfo=CreateDefaultCollection();
CurrentWebServiceInfo.Name=nService.getAttribute("name");
CurrentWebServiceInfo.IsUsable=false;
CurrentWebServiceInfo.UnusableReason+="WebService不支持soaphttp";
var nsPort=nService.selectNodes("port");
var nPort,port_name,port_binding,nBinding,nBindingSoap,port_binding_name,
nPortAddress,port_address_location,
nsOperation,nOperation,nOperationSoap;
for(var i=0;i<nsPort.length;i++)
{
nPort=nsPort.item(i);
port_name=nPort.getAttribute("name");
port_binding=nPort.getAttribute("binding");
nBinding=xdWSDL.selectSingleNode(xdrootpath+GetNodeName(collPf["wsdl"],"binding")+"[@name$eq$'"+port_name+"'&&@type$eq$'"+port_binding+"']");
nBindingSoap=nBinding.selectSingleNode(GetNodeName(collPf["soap"],"binding"));
if(IsNull(nBindingSoap))continue;
ASSERT(collNs["soaphttp"]==nBindingSoap.getAttribute("transport"),"nBindingSoap的transport不为"+collNs["soaphttp"]);
port_binding_name=TagNameToBaseName(port_binding);
nPortAddress=nPort.selectSingleNode(GetNodeName(collPf["soap"],"address"));
port_address_location=nPortAddress.getAttribute("location");
CurrentWebServiceInfo.IsUsable=true;
CurrentWebServiceInfo.UnusableReason="";
CurrentWebServiceInfo.URL=port_address_location;
nsOperation=nBinding.selectNodes("operation");
for(var j=0;j<nsOperation.length;j++)
{
nOperation=nsOperation.item(j);
nOperationSoap=nOperation.selectSingleNode(GetNodeName(collPf["soap"],"operation"));
ASSERT(
"literal"==
nOperation.selectSingleNode(GetNodeName(collPf["wsdl"],"input")+"/"+GetNodeName(collPf["soap"],"body"))
.getAttribute("use"),
"还没有对非literal的情况进行处理"
);
CurrentWebServiceInfo.CollWebMethodInfo._add(CreateWebMethodInfo());
}
}
delete nsPort;delete i;delete nPort;delete port_name;delete port_binding;
delete nBinding;delete nBindingSoap;delete port_binding_name;
delete nPortAddress;delete port_address_location;delete j;
delete nsOperation;delete nOperation;delete nOperationSoap;
CurrentWebServiceInfo.Create=(function(){
if(!CurrentWebServiceInfo.IsUsable)
ThrowError("WebService:"+CurrentWebServiceInfo.Name+"不能被创建\n"+CurrentWebServiceInfo.UnusableReason);
var WebService=new Object();
for(var i=0;i<CurrentWebServiceInfo.CollWebMethodInfo.Length;i++)
{
var wmi=CurrentWebServiceInfo.CollWebMethodInfo.Item(i);
if(IsObjectPPT(wmi.Name))
{
BREAKPOINT("WebMethod的名字"+wmi.Name+"和JScript的对象属性名冲突\n该WebMethod不被创建");
continue;
}
WebService[wmi.Name]=wmi.Create();
}
return WebService;
});
return CurrentWebServiceInfo;
function CreateWebMethodInfo()
{
var CurrentWebMethodInfo=new Object();
CurrentWebMethodInfo.CollParamInInfo=CreateDefaultCollection();
CurrentWebMethodInfo.CollParamOutInfo=CreateDefaultCollection();
CurrentWebMethodInfo.Name=nOperation.getAttribute("name");
CurrentWebMethodInfo.XMLNS=
CurrentWebMethodInfo.SoapAction=nOperationSoap.getAttribute("soapAction");
CurrentWebMethodInfo.IsUsable=true;
CurrentWebMethodInfo.UnusableReason="";
var nPortType=xdWSDL.selectSingleNode(xdrootpath+GetNodeName(collPf["wsdl"],"portType")+"[@name$eq$'"+port_binding_name+"']");
var nPortTypeOperation=nPortType.selectSingleNode(GetNodeName(collPf["wsdl"],"operation")+"[@name$eq$'"+CurrentWebMethodInfo.Name+"']");
var message_input=nPortTypeOperation.selectSingleNode(GetNodeName(collPf["wsdl"],"input")).getAttribute("message");
var message_output=nPortTypeOperation.selectSingleNode(GetNodeName(collPf["wsdl"],"output")).getAttribute("message");
var nMessageInput=xdWSDL.selectSingleNode(xdrootpath+GetNodeName(collPf["wsdl"],"message")+"[@name$eq$'"+TagNameToBaseName(message_input)+"']");
var nMessageOutput=xdWSDL.selectSingleNode(xdrootpath+GetNodeName(collPf["wsdl"],"message")+"[@name$eq$'"+TagNameToBaseName(message_output)+"']");
var element_input=nMessageInput.selectSingleNode(GetNodeName(collPf["wsdl"],"part")).getAttribute("element");
var element_output=nMessageOutput.selectSingleNode(GetNodeName(collPf["wsdl"],"part")).getAttribute("element");
var nSchema=xdWSDL.selectSingleNode(xdrootpath+GetNodeName(collPf["wsdl"],"types")+"/"+GetNodeName(collPf["xsd"],"schema")+"[@targetNamespace$eq$'"+collNs["target"]+"']");
var nSchemaInput=nSchema.selectSingleNode(GetNodeName(collPf["xsd"],"element")+"[@name$eq$'"+TagNameToBaseName(element_input)+"']");
var nSchemaOutput=nSchema.selectSingleNode(GetNodeName(collPf["xsd"],"element")+"[@name$eq$'"+TagNameToBaseName(element_output)+"']");
CurrentWebMethodInfo.NameInput=nSchemaInput.getAttribute("name");
CurrentWebMethodInfo.NameOutput=nSchemaOutput.getAttribute("name");
var nsInputSequence=nSchemaInput.selectNodes(GetNodeName(collPf["xsd"],"complexType")+"/"+GetNodeName(collPf["xsd"],"sequence")+"/"+GetNodeName(collPf["xsd"],"element"));
var nSequence;
for(var i=0;i<nsInputSequence.length;i++)
{
nSequence=nsInputSequence.item(i);
CurrentWebMethodInfo.CollParamInInfo._add(CreateParamInfo());
}
var nsOutputSequence=nSchemaOutput.selectNodes(GetNodeName(collPf["xsd"],"complexType")+"/"+GetNodeName(collPf["xsd"],"sequence")+"/"+GetNodeName(collPf["xsd"],"element"));
for(var i=0;i<nsOutputSequence.length;i++)
{
nSequence=nsOutputSequence.item(i);
CurrentWebMethodInfo.CollParamOutInfo._add(CreateParamInfo());
}
if(CurrentWebMethodInfo.IsUsable==false)
{
CurrentWebServiceInfo.IsUsable=false;
CurrentWebServiceInfo.UnusableReason+="\n["+CurrentWebServiceInfo.Name+":"+CurrentWebMethodInfo.UnusableReason+"]";
}
delete nPortType;delete nPortTypeOperation;delete message_input;delete message_output;
delete nMessageInput;delete nMessageOutput;delete element_input;delete element_output;
delete nSchema;delete nSchemaInput;delete nSchemaOutput;
delete nsInputSequence;delete nsOutputSequence;delete nSequence;delete i;
CurrentWebMethodInfo.Create=(function(){
return FunctionSpace();
function FunctionSpace()
{
function InnerCreateCall(a){
return FunctionSpace();
function FunctionSpace()
{
var async=a;
var isReady=a?false:true;
var isCalled=false;
var xh=new ActiveXObject("Microsoft.XMLHTTP");
xh.onreadystatechange=onreadystatechange;
var xdr=new ActiveXObject("Microsoft.XMLDOM");
function onreadystatechange(){
if(xh.readyState!=4)return;
if(isReady==false)RecieveData();
}
function RecieveData()
{
isReady=true;
xdr.loadXML(xh.responseXML.xml);
xh=null;
AsyncCall.onready(AsyncCall);
}
function Send(args){
if(CurrentWebMethodInfo.CollParamInInfo.Length!=args.length)
ThrowError(CurrentWebMethodInfo.Name+":调用错误\n只能是"+CurrentWebMethodInfo.CollParamInInfo.Length+"个参数");
var xd=new ActiveXObject("Microsoft.XMLDOM");
xd.loadXML(
'<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/">\
<soap:Body></soap:Body></soap:Envelope>'
);
var nwm=xd.createElement(CurrentWebMethodInfo.NameInput);
nwm.setAttribute("xmlns",CurrentSoapClient.XMLNS);
xd.documentElement.firstChild.appendChild(nwm);
for(var i=0;i<CurrentWebMethodInfo.CollParamInInfo.Length;i++)
{
var ParamInfo=CurrentWebMethodInfo.CollParamInInfo.Item(i);
var np=xd.createElement(ParamInfo.Name);
np.text=ParamInfo.CreateFromValue(args[i]).String;
nwm.appendChild(np);
}
try{
xh.open("POST",CurrentWebServiceInfo.URL,async,CurrentSoapClient.UserName,CurrentSoapClient.Passwrod);
}catch(x){
ThrowError("调用WebMethod:"+CurrentWebMethodInfo.Name+"失败\n"+x.description);
}
xh.setRequestHeader("Content-Type","text/xml; charset=UTF-8");
xh.setRequestHeader("SOAPAction",'"'+CurrentWebMethodInfo.SoapAction+'"');
xh.send('<?xml version="1.0" encoding="UTF-8"?>'+xd.xml);
isCalled=true;
if(async==false)RecieveData();
return AsyncCall;
}
function Get(){
if(xdr.parseError.errorCode)
ThrowError("调用WebMethod:"+CurrentWebMethodInfo.Name+"返回错误");
var body=xdr.documentElement.firstChild;
if(body.firstChild.namespaceURI=="http://schemas.xmlsoap.org/soap/envelope/")
ThrowError(body.firstChild.selectSingleNode("faultstring").text);
var nsResult=body.selectSingleNode(CurrentWebMethodInfo.NameOutput).selectNodes("*");
var CollReturnValue=CreateDefaultCollection();
for(var i=0;i<nsResult.length;i++)
{
var nResult=nsResult.item(i);
var ParamInfo=CurrentWebMethodInfo.CollParamOutInfo.Item(i);
CollReturnValue._add(ParamInfo.CreateFromString(nResult.text));
}
return CollReturnValue;
}
function AsyncCall(){
return AsyncCall.Invoke(AsyncCall.arguments);
}
function AsyncCall.GetWebMethod(){
return Method;
}
function AsyncCall.Call(){
return AsyncCall.Invoke(AsyncCall.Call.arguments);
}
function AsyncCall.valueOf(){
return AsyncCall.toString();
}
function AsyncCall.toString(){
return "[WebMethod(Name=\""+CurrentWebMethodInfo.Name+"\")]";
}
function AsyncCall.IsReady(){
return isReady;
}
function AsyncCall.IsReady.valueOf(){return AsyncCall.IsReady();}
function AsyncCall.IsReady.toString(){return AsyncCall.IsReady();}
function AsyncCall.Invoke(args){
if(async)
{
if(isCalled)ThrowError("Async Call 对象只能使用一次");
return Send(args);
}
Send(args);
return Get();
}
function AsyncCall.GetResult(){
if(isReady==false)ThrowError(CurrentWebMethodInfo.Name+":结果还没有返回");
return Get();
}
function AsyncCall.onready(objCall){}
return AsyncCall;
}
}
function Method(){
return InnerCreateCall(false).Invoke(Method.arguments);
}
function Method.valueOf(){
return Method.toString();
}
function Method.toString(){
return "[WebMethod(Name=\""+CurrentWebMethodInfo.Name+"\")]";
}
function Method.CreateCall()
{
return InnerCreateCall(true);
}
return Method;
};
});
return CurrentWebMethodInfo;
function CreateParamInfo()
{
var CurrentParamInfo=new Object();
CurrentParamInfo.Name=nSequence.getAttribute("name");
CurrentParamInfo.Type=TagNameToBaseName(nSequence.getAttribute("type"));
CurrentParamInfo.TypeNS=(function(){
var prefix=TagNameToPrefix(nSequence.getAttribute("type"));
for(var i in collPf)
{
if(collPf[i]==prefix)return collNs[i];
}
//ThrowError("前缀"+prefix+"找不到名字空间");
return toString(xdWSDL.documentElement.getAttribute("xmlns:"+prefix));
})();
if(CurrentParamInfo.TypeNS!=collNs["xsd"])
{
CurrentWebMethodInfo.IsUsable=false;
CurrentWebMethodInfo.UnusableReason+="["+CurrentWebMethodInfo.Name+":"+CurrentParamInfo.Name+"不支持的数据类型namespace:"+CurrentParamInfo.TypeNS+"]";
}
(function(){
var arr=new Array("string","boolean","int","float","double");
for(var i=0;i<arr.length;i++)
{
if(arr[i]==CurrentWebMethodInfo.Type)
return;
}
CurrentWebMethodInfo.IsUsable=false;
CurrentWebMethodInfo.UnusableReason+="["+CurrentWebMethodInfo.Name+":"+CurrentParamInfo.Name+"不支持的数据类型:"+CurrentWebMethodInfo.Type+"]";
});
CurrentParamInfo.ValueFromString=(function(v){
ASSERT("string"==typeof(v),"SoapTypes.ValueFromString:str不是string");
/*
checking...CurrentParamInfo.TypeNS
...nothing to check now...
*/
switch(CurrentParamInfo.Type)
{
case "string":
return v;
case "int":
return parseInt(v);
case "float":
case "double":
return parseFloat(v);
case "boolean":
if(v.toLowerCase()=="false")return false;
if(v.toLowerCase()=="true")return true;
default:
ThrowError("SoapTypes.ValueFromString:boolean类型错误,值为"+v);
}
});
CurrentParamInfo.StringFromValue=(function(v){
if(IsNull(v))return "";
return VarToString(v);
});
CurrentParamInfo.CreateFromString=(function(v){
return CreateParam(true,v);
});
CurrentParamInfo.CreateFromValue=(function(v){
return CreateParam(false,v);
});
function CreateParam(bystring,v)
{
var param=new Object();
param.Name=CurrentParamInfo.Name;
param.Type=CurrentParamInfo.Type;
param.TypeNS=CurrentParamInfo.TypeNS;
if(bystring){
param.String=v;
param.Value=CurrentParamInfo.ValueFromString(v);
}
else{
param.Value=v;
param.String=CurrentParamInfo.StringFromValue(v);
}
param.valueOf=(function(){
return param.Value;
});
param.toString=(function(){
return param.String;
});
return param;
}
return CurrentParamInfo;
}
}
}
}
}
function JScriptSoapClient.valueOf(){
return JScriptSoapClient.toString();
}
function JScriptSoapClient.toString(){
return "JScriptSoapClient 0.20 Beta By http://www.lostinet.com";
}
function JScriptSoapClient.AsyncLoad(func,url,username,password)
{
ASSERT(IsFunction(func),"AsyncLoadJScriptSoapClient:参数无效");
ASSERT(IsString(url),"AsyncLoadJScriptSoapClient:参数无效");
var idLoad=new Date().getTime()*1000000+Math.floor(Math.random()*1000000)
var xh=new ActiveXObject("Microsoft.XMLHTTP");
xh.onreadystatechange=OnReadyStateChange;
xh.open("GET",url,true,username,password);
xh.send();
function OnReadyStateChange()
{
if(xh.readyState!=4)return;
var xd=xh.responseXML;
if(xd.parseError.errorCode)
{
func(null,url,idLoad);
}
func(new JScriptSoapClient(url,username,password,xd.xml),url,idLoad);
xh=null;
}
}