topical media & game development

talk show tell print

professional-javascript-17-MozWebServiceExample2.htm / htm

          <title>Mozilla Web Service Example</title>
          <script type="text/javascript">
          var sWSDL = "";
                                  var sPort = "TemperaturePort";
          var oProxy = null;
                                  //the callback object for proxy creation
          var oProxyCreateCallback = {
              onLoad: function(oCreatedProxy) {
                  oProxy = oCreatedProxy;
              onError: function(sError) {
                                  //the callback object for the getTemp() method
          var oGetTempCallback = {
              getTempCallback: function (iDegrees) {
                              alert("It is currently " + iDegrees + " degrees in that zip code.");
                                  //creates the proxy
          function createProxy() {
             try {
                  var oFactory = new WebServiceProxyFactory();
                  oFactory.createProxyAsync(sWSDL, sPort, "", true, oProxyCreateCallback);
              } catch (oError) {
                                  //calls the web srevice
          function callWebService() {                        
              if (oProxy) {
                  var sZip = document.getElementById("txtZip").value;    
              } else {
                  alert("Proxy not available.");
                                  //create the proxy when the page loads so it will be ready 
                                  //when the button is pressed
                                  window.onload = createProxy;
                      <p>This example uses the Mozilla <acronym title="Web Services Description Language">WSDL</acronym> proxy
                                  to make an <em>asynchronous</em> call to <code>getTemp</code>.
          <p><input type="text" id="txtZip" size="10" /><input type="button" value="Get Temperature" onclick="callWebService()" />

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.