📄 webservicetest.xml
字号:
<?xml version="1.0"?><!-- A test case that calls a simple web service--><Application> <Window caption="Web Service Test" width="275" height="100"/> <Resources> <Script><![CDATA[function WebServiceTest() { var win = application.getWindow(); this.createWebService(); // create the GUI components this.inputField1 = new BiTextField("10"); this.inputField2 = new BiTextField("3"); this.resultField = new BiTextField; this.operandButton = new BiButton("/"); this.resultButton = new BiButton("="); this.statusBar = new BiStatusBar; this.statusSection = new BiStatusBarPanel; this.inputField1.setAlign("right"); this.inputField2.setAlign("right"); this.resultField.setAlign("right"); this.resultField.setReadOnly(true); this.inputField1.setTabIndex(1); this.operandButton.setTabIndex(2); this.inputField2.setTabIndex(3); this.resultButton.setTabIndex(4); this.resultField.setTabIndex(5); win.add(this.inputField1); win.add(this.operandButton); win.add(this.inputField2); win.add(this.resultButton); win.add(this.resultField); this.statusBar.add(this.statusSection); win.add(this.statusBar); this.statusSection.setLeft(0); this.statusSection.setRight(0); this.statusSection.setPadding(2, 1); // make pressing Enter dispatch the action for the result button win.setAcceptButton(this.resultButton); // do the layout this.inputField1.setLocation(5, 7); this.inputField1.setWidth(50); this.operandButton.setLocation(this.inputField1.getLeft() + this.inputField1.getWidth() + 5, 5); this.operandButton.setWidth(20); this.inputField2.setLocation(this.operandButton.getLeft() + this.operandButton.getWidth() + 5, 7); this.inputField2.setWidth(50); this.resultButton.setLocation(this.inputField2.getLeft() + this.inputField2.getWidth() + 5, 5); this.resultButton.setWidth(20); this.resultField.setLocation(this.resultButton.getLeft() + this.resultButton.getWidth() + 5, 7); this.resultField.setRight(5); this.resultButton.addEventListener("action", this.getResult, this); // Create a drop down menu for the operand button var m = new BiMenu; var operands = ["+", "-", "*", "/"]; var tmp; for (var i = 0; i < operands.length; i++) { m.add( tmp = new BiMenuItem(operands[i]) ); tmp.addEventListener("action", function (e) { this.operandButton.setText( e.getTarget().getText() ); }, this); } // asssign the menu as a context menu and also show the menu when clicking // the button this.operandButton.setContextMenu(m); this.operandButton.addEventListener("action", function (e) { m.setLocation(this.operandButton.getScreenLeft(), this.operandButton.getScreenTop() + this.operandButton.getHeight()); m.setVisible(true); }, this);}WebServiceTest.main = function () { new WebServiceTest; };// WSDL URIs must be absoluteWebServiceTest.WSDL_URI = String( new BiUri( application.getAdfPath(), "../../services/MathService.asmx?WSDL" ) );// WebServiceTest.WSDL_URI = "http://www.bindows.net/services/MathService.asmx?WSDL";WebServiceTest.prototype._serviceAvailable = false;WebServiceTest.prototype.createWebService = function () { var oThis = this; this.webService = new BiWebService; // we need to wait until the web service is ready this.webService.onreadystatechange = function () { if ( this.readyState == "complete" ) { oThis.onReadyStateComplete(); } }; // called when the WSDL has been loaded this.webService.onserviceavailable = function () { oThis.onServiceAvailable(window.event); }; // hook up call back this.webService.onresult = function () { oThis.onResult(window.event.result); };};WebServiceTest.prototype.isWebServiceReady = function () { return this.webService.readyState == "complete" && this._serviceAvailable;};WebServiceTest.prototype.onReadyStateComplete = function () { this.statusSection.setText("Looking up WSDL"); // once complete we can initialize the service this.webService.useService(WebServiceTest.WSDL_URI, "MathService");};WebServiceTest.prototype.onServiceAvailable = function (e) { this._serviceAvailable = e.serviceAvailable; // once ready we can initialize the service if ( this.isWebServiceReady() ) this.statusSection.setText("Done"); else this.statusSection.setText("Failed to initialize web service");};WebServiceTest.prototype.onResult = function (oResult) { if (oResult.error) { this.statusSection.setText("Done but with errors"); alert("Got an error\n\n" + oResult.errorDetail.string); } else { // bug in MS Behavior HTC that does not correctly map Infinity // this is not usually an issue but for this little app it is nifty // to correctly support this if (oResult.value == "INF") oResult.value = Infinity; this.resultField.setText(oResult.value); this.statusSection.setText("Done"); }};WebServiceTest.prototype.getResult = function () { // find the name of the function to call var sFunctionName; switch (this.operandButton.getText()) { case "+": sFunctionName = "add"; break; case "-": sFunctionName = "sub"; break; case "*": sFunctionName = "mul"; break; case "/": sFunctionName = "div"; break; } if ( this.isWebServiceReady() ) { this.statusSection.setText("Calling " + sFunctionName + "..."); // call the service using this name this.webService.MathService.callService(sFunctionName, Number(this.inputField1.getText()), Number(this.inputField2.getText())); } else { this.statusSection.setText("Web service is not ready"); alert("Web service is not ready"); }}; ]]></Script> </Resources></Application>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -