Quoth Tim Lucas:

Although for a real world app you'd want to write an abstraction layer 
so as to take advantage of moz's native web service support.

Considering you'd never be doing this on a public website anyway it 
would probably make more sense having it IE or Moz specific (not that 
the abstraction layer wouldn't be great -- but good luck convincing the 
client of the ROI).

--

This is what I'm trying to do; it instantiates the behavior file if
you're using IE; else it attempts the gecko code. I don't know what I'll
do about Opera. I can get the gecko code working if I return a string,
but any kind of complex data type (array, struct, etc.)  bombs out.

Find attached both the library I'm in the midst of tearing my hair out
over and the WSDL file of the test component; if you've got the
webservice behavior you can try it out.
/**
 * class WebService
 * Consumes a webservice in IE or Gecko-based browsers
 * 
 * @param   serviceURL       The URL of the WSDL interface to the webservice
 * @param   serviceName      The friendly name of the service - for ColdFusion
                                 webservices, this includes the 'CFC'
 * @param   methodName       The method of the webservice to call
 * @param   responseHandler  A function which processes the webservice response
 * @param   errorHandler     A function which handles an error returned from 
                                 the webservice
 */
function WebService (serviceURL, serviceName, methodName, responseHandler, 
errorHandler) {
        var listener = {};
        if (document.all) {  // IE-specific code
                /* Instantiate the behavior */
                service = document.createElement('div');
                service.id = 'service';
                service.webServiceBehaviorLoaded = false;
                service.style.behavior = 'url(webservice.htc)';
                service.style.display = 'none';
                document.documentElement.appendChild(service);
                /* Assign the handlers to the 'listener' object (in IE, it's actually 
of type 'call') */
                service.onresult = function (wsObj) {
                        if (wsObj.error) {
                                errorHandler(wsObj);
                        } else {
                                responseHandler(wsObj);
                        }
                }
                listener.funcName = methodName;
                // always use asynchronous connections - synchronous are not supported 
in IE
                listener.async = true;
                /* The method of the WebService class which actually calls the service 
*/
                this.call = function (args) {
                        if (args) {
                                listener.params = args;
                        }
                        service.useService(serviceURL, serviceName);
                        j = service[serviceName].callService(service.onresult, 
listener);
                }
        } else {
                /* instantiate the listener object - the service variable here is of 
type 'proxy' */
                listener.onLoad = function (aProxy) {
                        service = aProxy;
                        service.setListener(listener);
                        alert('service created');
                };
                /* assign the handlers (in gecko, it's of type 'listener') */
                listener.onError = errorHandler;
                listener[methodName + 'Callback'] = responseHandler;
                /* attempt to create the proxy - always use asynchronous, as 
synchronous is not yet supported */
                try {
                        var factory = new WebServiceProxyFactory();
                        factory.createProxyAsync(serviceURL, serviceName, "", true, 
listener);
                } catch (ex) {
                        alert(ex);
                }
                /* The method of the WebService class which actually calls the service 
*/
                this.call = function (args) {
                        if (service != null) {
                                if (args) {
                                        service[methodName](args);
                                } else {
                                        service[methodName]();
                                }
                        } else {
                                alert("Error: Service set up not complete!");
                        }
                }
        }
}

/* dummy error handler; define function debug() elsewhere */
function wsError (wsReturn) {
        alert('wsError');
        switch (typeof(wsReturn)) {
                case 'string':
                        debug(wsReturn);
                        break;
                case 'object':
                        alert('debugging returned error');
                        debug(wsReturn);
        }
}

/* dummy response handler; define function debug() elsewhere */
function wsResponse (wsReturn) {
        alert('wsResponse');
        switch (typeof(wsReturn)) {
                case 'string':
                        debug(wsReturn);
                        break;
                case 'object':
                        alert('debugging returned object');
                        debug(wsReturn);
        }
}

Attachment: ws.wsdl
Description: ws.wsdl

Reply via email to