Previous Page | Next Page

Importing XML Documents

Importing Web Service Results Using the WSDL Markup Type (Preproduction)


What Is a Web Service?

A Web service is a program that runs over a network and enables computers to exchange information over the Internet. For example, a Web service can provide information such as weather data and stock quotes. When the Web service is created, a Web Services Description Language (WSDL) file is created as well. The WSDL file is an XML document that describes the available services, the input and output parameters for the Web service, and other information for interacting with the Web service. WSDL is developed jointly by Microsoft and IBM.


Understanding How to Import Web Service Results

Specifying the WSDL markup type enables the XML LIBNAME engine to invoke a Web service and import the Web service results. The WSDL markup type interacts with a WSDL file that supports the markup standards of WSDL 1.1.

The process of importing Web service results requires several steps and transmissions of data in the following order:

  1. In the LIBNAME statement, you must specify the XML92 engine nickname and the WSDL markup type to access a WSDL file. See LIBNAME Statement Syntax. In addition, in the LIBNAME statement, you can specify WSDL options for importing Web service results. See Options.

  2. Before the XML LIBNAME engine can invoke a Web service and import the Web service results, you must determine the contents of the WSDL file. Use the DATASETS procedure, and then the CONTENTS procedure. PROC DATASETS translates the Web service descriptions in the WSDL file markup into SAS data set member names. Then, by submitting PROC CONTENTS for the input parameters member name, you determine the contents of the Web service input parameters such as the variable names and types.

  3. After you have the information that you need to interact with the Web service, you must create two SAS data sets. The first data set must match the contents of the Web service input parameters. The second data set will contain the Web service results.

    When you create the SAS data set for the Web service results, this step submits the input parameters and imports the Web service results. To create the SAS data set for the Web service results, use the SET statement:

    • Specify the libref from the LIBNAME statement (from step 1).

    • Specify the member name of the Web service results (from step 2).

    • Include the PARMS= data set option to specify the name of the SAS data set that you created that matches the contents of the Web service input parameters (from step 3).

  4. The Web service results SAS data set now contains the results.


Importing Web Service Results

This example illustrates how to import the Web service results that are described by a WSDL file.

The following SAS program accesses the WSDL file to list the Web service descriptions, creates the necessary SAS data sets to contain the input and output parameters, and then imports the Web service results. The Web service that is invoked in this example adds the values for X and Y.

filename wsdl url "http://t2824/AddService.asmx?WSDL"; 1 

libname wsdl xml92 xmltype=wsdl; 2 

proc datasets library=wsdl details; 3 
run;

proc contents data=wsdl.Add varnum; 4 
run;

proc contents data=wsdl.AddResponse varnum;  4 
run;

data work.add; 5 
   x=1;
   y=1;
run;

data work.resp; 6 
   set wsdl.AddResponse (parms=work.add);
run;

proc contents data=work.resp varnum; 7 
run;

proc print data=work.resp; 8 
run;

  1. The FILENAME statement assigns the fileref WSDL to the WSDL file.

  2. The LIBNAME statement uses the WSDL fileref as the libref to reference the WSDL file, specifies the XML92 engine nickname, and specifies the WSDL markup type. To specify a fileref for the WSDL file that does not match the libref, you can use the XMLFILEREF= option.

  3. The DATASETS procedure lists, as SAS data sets, the Web service descriptions that are in the WSDL file markup. The results in PROC DATASETS Output show that the Web service has both input parameters and results. The engine translates these as two SAS data sets WSDL.Add and WSDL.AddResponse. The data set label tells you that Add is the input parameters, and AddResponse is the results.

    The DETAILS option includes information in the log about the number of observations, variables, indexes, and data set labels. The input parameters data set contains two variables, and the results data set contains one variable.

  4. The two CONTENTS procedures describe the contents of the Web service input parameters and results. The VARNUM option prints a list of the variables by their position in the data set. The input parameters data set is shown in PROC CONTENTS Output for WSDL.Add, and the results data set is shown in PROC CONTENTS Output for WSDL.AddResponse.

    The data set label tells you that Add is the input parameters data set, and AddResponse is the results data set. In addition, each PROC CONTENTS output contains the variable attributes such as name, type, and length. The variable label lists the column type as defined in the WSDL file.

  5. The first DATA step creates a temporary SAS data set named WORK.ADD that contains the input parameters to be submitted to the Web service. The data set must be created as described in the PROC CONTENTS output for WSDL.Add, which means that WORK.ADD contains the numeric variables X and Y. The value for X and the value for Y, which is 1 for each variable, will be submitted to the Web service.

  6. The second DATA step creates a temporary SAS data set named WORK.RESP to contain the results from the Web service.

    1. The SET statement specifies the libref WSDL from the LIBNAME statement, the member name of the Web service results SAS data set (WSDL.AddResponse), and the PARMS= data set option. The PARMS= data set option specifies the name of the SAS data set to be submitted to the Web service (WORK.ADD).

      The SET statement causes the engine to read the input parameters that are contained in the SAS data set that is specified in the PARMS= data set option, which is WORK.ADD. In addition, the engine invokes the Web service.

    2. The engine retrieves the response from the Web service, and imports the results into the WORK.RESP data set.

  7. PROC CONTENTS describes the contents of WORK.RESP, which contains one variable named AddResult.

  8. PROC PRINT prints the observations in WORK.RESP, which contains the Web service Add Result of 2.

PROC DATASETS Output

                                           Directory

                        Libref         WSDL
                        Engine         XML92
                        Physical Name  http://t2824/AddService.asmx?WSDL
                        XMLType        Web Services Description Language
                        Version        .


                          Member  Obs, Entries
          #  Name         Type     or Indexes   Vars  Label

          1  Add          DATA         0         2    WebService Add - Input parameters
          2  AddResponse  DATA         0         1    WebService Add - Return results

PROC CONTENTS Output for WSDL.Add

                                         The SAS System                                                         1

                                     The CONTENTS Procedure

      Data Set Name        WSDL.Add                                Observations          0
      Member Type          DATA                                    Variables             2
      Engine               XML92                                   Indexes               0
      Created              .                                       Observation Length    0
      Last Modified        .                                       Deleted Observations  0
      Protection                                                   Compressed            NO
      Data Set Type                                                Sorted                NO
      Label                WebService Add - Input parameters
      Data Representation  Default
      Encoding             Default


                                Engine/Host Dependent Information

                                         Table Name  Add
                                         Table Path  .


                                   Variables in Creation Order

                        #    Variable    Type    Len    Label

                        1    x           Num       8    datatype=integer
                        2    y           Num       8    datatype=integer

PROC CONTENTS Output for WSDL.AddResponse

                                         The SAS System                                                         2

                                     The CONTENTS Procedure

      Data Set Name        WSDL.AddResponse                        Observations          0
      Member Type          DATA                                    Variables             1
      Engine               XML92                                   Indexes               0
      Created              .                                       Observation Length    0
      Last Modified        .                                       Deleted Observations  0
      Protection                                                   Compressed            NO
      Data Set Type                                                Sorted                NO
      Label                WebService Add - Return results
      Data Representation  Default
      Encoding             Default


                                Engine/Host Dependent Information

                                     Table Name  AddResponse
                                     Table Path  .


                                   Variables in Creation Order

                        #    Variable     Type    Len    Label

                        1    AddResult    Num       8    datatype=integer

PROC CONTENTS Output for WORK.RESP

                                         The SAS System                                                         3

                                     The CONTENTS Procedure

      Data Set Name        WORK.RESP                              Observations          1
      Member Type          DATA                                   Variables             1
      Engine               V9                                     Indexes               0
      Created              Friday, September 11, 2009 03:05:39 PM Observation Length    8
      Last Modified        Friday, September 11, 2009 03:05:39 PM Deleted Observations  0
      Protection                                                  Compressed            NO
      Data Set Type                                               Sorted                NO
      Label
      Data Representation  WINDOWS_32
      Encoding             wlatin1  Western (Windows)


                                Engine/Host Dependent Information

Data Set Page Size          4096
Number of Data Set Pages    1
First Data Page             1
Max Obs per Page            501
Obs in First Data Page      1
Number of Data Set Repairs  0
Filename                    C:\DOCUME~1\xxxxxx\LOCALS~1\Temp\SAS
                            Temporary Files\_TD316\resp.sas7bdat
Release Created             9.0202M3
Host Created                XP_PRO


                                   Variables in Creation Order

                        #    Variable     Type    Len    Label

                        1    AddResult    Num       8    datatype=integer

PROC PRINT Output for WORK.RESP

                                         The SAS System                                            4

                                                   Add
                                          Obs    Result

                                           1        2

Previous Page | Next Page | Top of Page