Lostinet works: JscriptsoapClientv0.20beta simply calls your webservice

zhaozj2021-02-17  48

// 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;

}

/ ************************************************** *************** /

jscriptsoapclient for .NET

0.203

SOAPCLIT JScript implementation, Beta version

lostinet

Lostinet@21cn.com; lostinet@chongjian.com;

http://www.lostinet.com/

Copyright Notice: This software can be released freely. Optimized modifications can also be optimized according to the specific situation. But please keep the author's related information.

/ ************************************************** *************** /

/ *

JScriptsoapClient for .NET

Author: Lost network [Lostinet]

Provide your webservice to provide easy-to-use call schemes

Temporarily only support String, Int, Float, Double, Boolean transmission

Instructions:

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.toT7tring ();

} 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

{

IF (Arr [i] === unknown) ThrowError ("VARVALUEOF () detected Valueof ring");

}

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;

}

// The judgment below is performed according to Varvalueof.

/ / Do not use these judgments before the variable is performed

// Reserved Application: For the extension of later 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 () Parameter Error");

VAR Arr = New Array ("Constructor", "HasownProperty", "InstanceOf", "IsprototypeOf", "Length", "Prototype", "Propertyisenumeramble", "Tostring", "Valueof");

For (var i = 0; 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 = "The following function is not specified error: / m" fs (). Caller);

ThrowError ("Assert - error: / n" msg);

}

Function Breakpoint (msg) {

MSG? NULL: (msg = fs (). Caller);

Msg = "BreakPoint, is there any abnormality?: / n" msg;

Try {

IF (Confirm (MSG) == false Return;

} catch (x) {

}

ThrowError ("BreakPoint Throwing Exception");

}

Function alert (msg) {

Try {

Window.alert (msg);

Return;

} catch (x) {}

Try {

WScript.echo (MSG);

Return;

} catch (x) {}

}

@ELSE

Function Assert (Mswetrue, 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, clear parameters

Function delegate (var1, var2)

{

IF (IscalledBynew (this)) throwerror ("New delegate () is a non-legal call mode");

IF (Isundefined (VAR1)) throwError ("delegate () parameter is invalid"); if (isundefined (var2)) {

Assert (isfunction (var1), "DELEGATE parameters are not function");

Return delegate_function (var1);

}

Assert (isfunction (var1) || isobject (var1), "DELEGATE parameter is not Object");

IF (Isstring (var2)) {

Assert (IsObject (var1 [var2]) || isfunction (var1 [var2]), "DELEGATE parameters are not method");

RETURN DELEGATE_METHOD (VAR1, VAR2);

}

Else {

Assert (isjscriptObject (var1), "Delegate's parameter is not jscriptObject");

Assert (isfunction (var 2), "DELEGATE parameters are not 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

Arr [arr.length] = "function.Arguments [" i "]";

For (; i

Arr [arr.length] = "function._arguments [" i "]";

Var struntuments = arr.join (",");

Var stres = "function._function (" strarguments ")"

stretage = "VAR f = (function () {return" stretage "}); f.delegate = function; f ()";

Return Eval (stres);

}

Function function.valueof () {return function ();

Function function.toString () {returnif function ();

Function function.preinvoke () {

Function._arguments = new arch;

Function.Setarguments (Function.Preinvoke.Arguments);

Return Function;

}

Function function.setrGuments (args) {

FOR (var i = 0; i

Function._arguments [i] = args [i];

Return Function;

}

Function function.detach () {

Function._function = NULL;

Function._arguments = NULL;

}

Function._function = func;

Function._arguments = new array (); returnif;

}

Function Delegate_method (Obj, Name)

{

Function function () {

IF (isnull (function._Object)) Return;

VAR arr = new array ();

For (i = 0; i

Arr [arr.length] = "function.Arguments [" i "]";

For (; i

Arr [arr.length] = "function._arguments [" i "]";

Var struntuments = arr.join (",");

Var stres = "function._oject." function._name "(" strarguments ")"

stretage = "VAR f = (function () {return" stretage "}); f.delegate = function; f ()";

Return Eval (stres);

}

Function function.valueof () {return function ();

Function function.toString () {returnif function ();

Function function.preinvoke () {

Function._arguments = new arch;

Function.Setarguments (Function.Preinvoke.Arguments);

Return Function;

}

Function function.setrGuments (args) {

FOR (var i = 0; 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 arch;

Return Function;

}

Function Delegate_VirtualMethod (Obj, FUNC)

{

Function function () {

IF (isnull (function._Object)) Return;

VAR arr = new array ();

For (i = 0; i

Arr [arr.length] = "function.Arguments [" i "]";

For (; i

Arr [arr.length] = "function._arguments [" i "]";

Var stratage (","); var ppt = "delegatevirtualmeth" new date (). gettime () "_" math.floor (math.random () * 1000000);

Function._Object [PPT] = FUNC;

Var res, error;

Var stres = "function._object." ppt "(" strarguments ")"

stretage = "VAR f = (function () {return" stretage "}); f.delegate = function; f ()";

Try {

Res = EVAL (stretage);

} 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 () {returnif function ();

Function function.preinvoke () {

Function._arguments = new arch;

Function.Setarguments (Function.Preinvoke.Arguments);

Return Function;

}

Function function.setrGuments (args) {

FOR (var i = 0; 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 arch;

Return Function;

}

}

Function delegate.queryDelegate ()

{/ Caution ObjdElegate.Valueof () recursive

Return fs (). Caller.caller.delegate;

}

Function JScriptsoapClient (WSDLURL, Username, Password, WSDLXML)

{

Function getnodename (prefix, basename) {

Assert (Isstring (BaseName), "getnodename () parameter error");

IF ("! = prefix) Return Prefix ": " BaseName;

Return Basename;

}

Function tagnametoprefix (tagname) {

Assert (Tagname) == "String", "TagnameTobaseName ():" tagname);

IF (":") == - 1) Return ""; return tagname.substr (0, tagname.indexof (":"));

}

Function tagnametobasename (tagname) {

Assert (Tagname) == "String", "TagnameTobaseName ():" tagname);

IF (tagname.indexof (":") == - 1) Return Tagname;

Return Tagname.substring (":") 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, "Cannot find 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: Can't arrive");

}

Function Collection._Add (Obj) {

Assert (isjscriptObject (obj) && isstring (obj.name), "CreateDefaultCollection :: Collection._ADD: Parameter Error");

Assert (obj.name! = Parseint (obj.name), "CreateDefaultCollection :: Collection._Add: obj.name can't be digital");

IF (iSJScriptObject (_coll [obj.name])) Return True;

_Coll [obj.name] = OBJ;

_LENGTH ;

Return True;

}

Return Collection;

}

}

Assert ((! Isnull (WSDLXML)) || (! Isnull (WSDLURL)), "JScriptsoapClient Parameters); 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 ("You can't get" WSDLURL "/ n may not be enough permissions");

Return XD;

}) ();

Break;

} catch (x) {

ThrowError

"Can't load WSDL: / N"

WSDLURL "/ N / N Detailed information: / 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.attribute;

For (var i = 0; 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 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, "Description of WebService" in WSDL ");

VAR NSERVICE;

For (VAR i = 0; i

{

NService = nsservice.Item (i);

CurrentsoapClient.collwebserviceInfo._add (CreateWebServiceInfo ());

}

Delete NService; delete i; delete xdrootpath;

@IF (@ debug == false)

Delete XDWSDL;

@end

Currentsoapclient.createwebservice = (function (name) {

Assert (Isstring (Name), "createWebservice () parameter is invalid");

Var wsi = currentsoapclient.collwebserviceInfo.ientm (name);

IF (ISNULL (WSI) "throwError (" Can't find WebService: " Name);

Return wsi.create ();

});

Return CurrentsoapClient;

Function CreatewebServiceInfo ()

{

// stack var currentwebserviceInfo

Var currentwebserviceInfo = new object ();

CurrentwebserviceInfo.collwebmethodInfo = cretedefaultcollection ();

CurrentwebserviceInfo.Name = Nservice.getaTRibute ("name");

CurrentwebserviceInfo.iSusable = false; currentwebserviceinfo.unusablereason = "WebService does not support 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

{

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 is not" Collns ["soaphttp"]);

Port_binding_name = tagnametobasename (port_binding);

NPORTADDRESS = Nport.selectsinglenode (GetNodename (Collpf ["SOAP"], "Address");

Port_address_location = nportaddress.getaTribute ("location");

CurrentwebserviceInfo.iusable = true;

CurrentwebserviceInfo.unusablereAason = "";

CurrentwebserviceInfo.URL = port_address_location;

nsoperation = nbinding.selectnodes ("Operation");

FOR (var j = 0; 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"),

"There is no treatment of non-Literal's situation"

);

CurrentwebserviceInfo.collwebmethodinfo._add (CreateWebMethodInfo ());

}

}

DELETE NSPORT; DELETE I; DELETE NPORT; Delete Port_BINDING;

Delete nbinding; delete nbindingsoap; delete port_binding_name;

DELETE NPORTADDRESS; DELETE Port_Address_location; delete J;

Delete NSOPERATION; Delete Noperations;

CurrentWebServiceInfo.create = (function () {

IF (! currentwebserviceinfo.iysusable)

ThrowError ("WebService:" CurrentWebServiceInfo.name "cannot be created /N" currentwebserviceInfo.unusablereason);

VAR webservice = new object ();

For (var i = 0; i

{

Var WMI = CurrentWebserviceInfo.collwebmethodinfo.ientm (i);

IF (ISObjectppt (WMI.NAME))

{

Breakpoint ("WebMethod" WMI.NAME "and JScript object attribute name conflict / N this webmedhod is not created");

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.GetaTRibute ("name");

CurrentWebMethodinfo.xmlns =

Currentwebmethodinfo.soapaction = NoPerationsoap.GetaTRibute ("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 NMESSAGEOUT = xdwsdl.selectsinglenode (xdrootpath getnodename (Collpf ["WSDL"], "Message" "[@ Name $ EQ $ '" tagnametobasename (Message_output) ");

Var element_input = nMessageInput.selectsinglenode (collpf ["wsdl"], "part")). GetAttribute ("Element");

Var element_output = NMESSAGEOUTPUT.SelectSinglenode (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 (collpf ["xsd"], "complexType") "/" getnodename (Collpf ["XSD"], "Sequence") "/" GetNodename (Collpf ["XSD" ], "Element"));

VAR NSEquence;

For (var i = 0; i

{

NSEQUENCE = NSINPUTSEQUENCE.ITEM (i);

CurrentwebmethodInfo.collparamininfo._add (createparaminfo ());

}

VAR nsoutputsequence = nschemaoutput.selectnodes (COLLPF ["XSD"], "ComplexType") "/" GetNodename (Collpf ["XSD"], "Sequence") "/" GetNodename (Collpf ["XSD" ], "Element"));

For (var i = 0; i

{

NSEQUENCE = NSOUTPUTSEQUENCE.ITEM (i);

CurrentwebmethodInfo.collparamoutinfo._add (createparaminfo ());

}

IF (currentwebmethodinfo.iusable == false)

{

CurrentwebserviceInfo.iusable = false;

CurrentwebserviceInfo.unusablereason = "/ n [" currentwebserviceinfo.name ":" CurrentWebMethodInfo.unusablereason "]";

}

DELETE NPOOPEOPERATION; DELETE Message_Input; Delete NMessageInput; delete nMessageoutput; delete element_Input; delete element_output;

Delete nschema; delete nschemaunt; delete nschemaoutput;

DELETE NSOUTSEQUENCE; 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 activ ("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 ": call error / n can only be" CurrentWebMethodInfo.collparamininfo.length "parameter");

Var xd = new activXObject ("Microsoft.xmldom");

XD.LoadXML

'

XMLns: xsd = "http://www.w3.org/2001/xmlschema" /

XMLns: soap = "http://schemas.xmlsoap.org/soap/envelop/"> /

'

);

VAR nwm = xd.createElement (currentwebmethodinfo.nameInput);

NWM.SetaTRibute ("XMLns", CurrentsoapClient.xmlns);

xd.documentelement.firstchild.Appendchild (NWM);

For (var i = 0; i

Var paraminfo = currentwebmethodinfo.collparamininfo.ientm (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 ("calls WebMethod:" currentwebmethodinfo.name "failed / n";

}

XH.SetRequestHeader ("Content-Type", "Text / XML; Charset = UTF-8");

XH.SetRequestHeader ("soapaction", '"' currentwebmethodinfo.soapaction '");

XH.send ('' xd.xml);

ISCALLED = TRUE;

IF (async == false) Recievedata ();

Return asyncCall;

}

Function get () {

IF (xdr.parseerror.errorcode)

ThrowError ("calls WebMethod:" CurrentWebMethodinfo.name "Return Error");

Var body = xdr.documentelement.firstchild;

IF (body.firstchild.namespaceuri == "http://schemas.xmlsoap.org/soap/envelop/")

ThrowError (Body.FirstChild.selectsinglenode ("Faultstring"). Text);

Var nsResult = body.selectsinglenode (currentwebmethodinfo.nameoutput) .SelectNodes ("*");

VAR COLLRETURNVALUE = CREATEDEFAULTCOLLECTION ();

For (var i = 0; i

{

VAR NRESULT = NSRESULT.ITEM (i);

Var paraminfo = currentwebmethodunfo.collparamoutinfo.ientm (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.toTOString ();

}

Function asyncCall.toString () {

Return "[WebMethod (name = /" " currentwebmethodinfo.name " / ")]"

}

Function asyncCall.isready () {

Return isready;

}

Function asyncCall.isready.valueof () {Return asyncCall.Isready ();

Function asyncCall.isready.toNCCALL.ISReady ();

Function asyncCall.Invoke (args) {

IF (async)

{

IF (IsCalled) ThrowError ("ASYNC CALL object can only be used once");

Return Send (ARGS);

}

Send (args);

Return get ();

}

Function asyncCall.getResult () {

IF (isready == false) throwerror (currentwebmethodinfo.name ": The result is not returned");

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 creageparaminfo ()

{

VAR CurrentParaminfo = New Object ();

CurrentParaminfo.name = nsequence.getattribute ("name");

CurrentParaminfo.type = tagnametobasename (NSEquence.GetaTRibute ("Type");

CurrentParaminfo.typens = (function () {

Var prefix = tagnametoprefix (nsequence.getattribute ("type"));

Var (Var i in COLLPF)

{

IF (COLLPF [i] == prefix) Return Collns [i];

}

// throwerror ("prefix" prefix "Can't find the name space");

Return Tostring (xdwsdl.documentelement.getattribute ("XMLns:" prefix));}) ();

IF (currentparaminfo.typens! = Collns ["xsd"])

{

Currentwebmethodinfo.iSusable = false;

Currentwebmethodinfo.unusablereason = "[" currentwebmethodinfo.naMe ":" currentparaminfo.name "does not support data type Namespace:" currentparaminfo.typens "]"

}

(function () {

Var Arr = New Array ("String", "Boolean", "INT", "float", "double");

For (var i = 0; i

{

IF (arr [i] == currentwebmethodinfo.type)

Return;

}

Currentwebmethodinfo.iSusable = false;

Currentwebmethodinfo.unusablereason = "[" currentwebmethodinfo.name ":" "not supported data type:" CurrentWebMethodInfo.type "]";

});

CurrentParaminfo.valuefromstring = (Function (V) {

Assert ("String" == TypeOf (V), "SOAPTYPES.VALUEFROMSTRING: STR is not 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 type error, value is" 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.toT7tring () {

Return "JScriptsoapClient 0.20 beta by http://www.lostinet.com";

}

Function JScriptsoapClient.asyncLoad (Func, URL, Username, Password)

{

Assert (ISFunction (FUNC), "AsyncLoadJscriptSoApClient: Parameter");

Assert (Isstring (URL), "AsyncLoadJscriptSoApClient: Parameter Invalid");

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;

}

}

转载请注明原文地址:https://www.9cbs.com/read-28515.html

New Post(0)