External Interfaces |
Simple M-File Example
The following M-file example provides a simple demonstration of programming with Web services. The script takes an array of zip codes and uses the temperature Web service to return the local temperatures. It then runs the max
, min
, and median
functions on the temperatures:
% Create array with zip codes for Arkansas zips = [71854 71901 72201 71601 72143 72904 72701 71971]; % Create empty array to contain temperature output temps = []; wsdlUrl = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'; if ~(exist(wsdlFile,'file') == 2) urlwrite(wsdlUrl,wsdlFile); end % Catch errors during class creation try % Create class from WSDL createClassFromWsdl(wsdlFile); catch % Throw error error('Unable to create WSDL class'); end ts = TemperatureService; % Iterate through zips array for z = zips try % Call the getTemp method t = getTemp(ts, z); catch % Throw error t = NaN; warning(lasterr); end % Concatenate temperature to temps array temps = horzcat(temps, t); end % Display temps array disp('Real-Time Temperatures for Arkansas'); disp(temps); % Display highest temperature disp('Highest Temperature in Arkansas'); disp(max(temps)); % Display lowest temperature disp('Lowest Temperature in Arkansas'); disp(min(temps)); % Display temps median disp('Median Temperature in Arkansas'); disp(median(temps)); % Display current date/time disp('Date and Time Created:'); disp(datestr(now));
Programming with Web Services | Serial Port I/O |
© 1994-2005 The MathWorks, Inc.