Module TestService.wo

     1Use cWebService.pkg
     2Use DataDict.pkg
     3Use VENDOR.DD
     4Use INVT.DD
     5Use CUSTOMER.DD
     6Use SALESP.DD
     7Use OrderHea.DD
     8Use OrderDtl.DD
     9
    10Object oTestService is a cWebService
    11
    12    Set psDocumentation to ;
    13        ("This is a Test Web Service. It contains a few simple operations " +;
    14         "demonstrating how to create a Visual DataFlex Web Service. "+;
    15         "To test any of these web services using your web browser, simply follow "+;
    16         "the link below for the specified service. "+;
    17         "You can also view the WSDL for this service by accessing the link to "+;
    18         "Service Description below. To create a new Web Service operation simply "+;
    19         "add a function in the oTestService Web Service object and select Publish. "+;
    20         "To learn more about creating Web Services in Visual DataFlex, please see the "+;
    21         "Web Services section in the Visual DataFlex Online Help.")
    22
    23    Set psServiceName to "TestService"
    24    Set psServiceURI to "http://www.visualdataflex.com/examples/testservice"
    25    Set psServiceTitle to "Visual DataFlex Test Web Service"
    26    Set psDescription to "Test Web Service"
    27
    28    Object Vendor_DD is a Vendor_DataDictionary
    29        Send DefineAllExtendedFields
    30    End_Object    // Vendor_DD
    31
    32    Object Invt_DD is a Invt_DataDictionary
    33        Set DDO_Server to Vendor_DD
    34        Send DefineAllExtendedFields
    35    End_Object    // Invt_DD
    36
    37    Object Customer_DD is a Customer_DataDictionary
    38        Send DefineAllExtendedFields
    39    End_Object    // Customer_DD
    40
    41    Object Salesp_DD is a Salesp_DataDictionary
    42        Send DefineAllExtendedFields
    43    End_Object    // Salesp_DD
    44
    45    Object OrderHea_DD is a OrderHea_DataDictionary
    46        Set DDO_Server to Customer_DD
    47        Set DDO_Server to Salesp_DD
    48        Send DefineAllExtendedFields
    49    End_Object    // OrderHea_DD
    50
    51    Object OrderDtl_DD is a OrderDtl_DataDictionary
    52        Set DDO_Server to OrderHea_DD
    53        Set DDO_Server to Invt_DD
    54        Send DefineAllExtendedFields
    55    End_Object    // OrderDtl_DD
    56
    57    Set Main_DD to Invt_DD
    58
    59    { Published = True  }
    60    { Description = "Returns a hello message using the name passed as the string."  }
    61    Function SayHello String sName Returns String
    62        String sReturn
    63             
    64        Move ("Hello," * sName +".") to sReturn
    65        
    66        Function_Return sReturn
    67    End_Function
    68    
    69    { Published = True  }
    70    { Description = "Returns a welcome message using the name passed as the string and IIS server variables."  }
    71    Function Welcome String sName Returns String
    72        String sReturn
    73        String sIPAddr sServer sLocalAddr
    74        
    75        Get ServerVariable "REMOTE_ADDR" to sIpAddr   
    76        Get ServerVariable "SERVER_NAME" to sServer
    77        Get ServerVariable "LOCAL_ADDR" to sLocalAddr
    78             
    79        Move ("Hello," * sName + ". This is" * sServer) to sReturn
    80        Move (sReturn * ". I see you're from" * sIPAddr * ". Welcome to" * sLocalAddr +"!") to sReturn
    81        
    82        Function_Return sReturn
    83    End_Function    
    84    
    85    { Published = True  }
    86    { Description = "Echoes back the string passed."  }
    87    Function Echo String echoString Returns String
    88        Function_Return echoString
    89    End_Function
    90
    91    { Published = True  }
    92    { Description = "Adds two numbers and returns the result."  }
    93    Function AddNumber Real number1 Real number2 Returns Real
    94        Function_Return (number1+number2)
    95    End_Function
    96
    97    { Published = True  }
    98    { Description = "Looks up the price of a particular inventory item. Example item identifiers, DT, GOLD, MAPS, OBM, RUNMTR."  }
    99    Function PriceQuote String itemID Returns Number
   100        Send Clear of Invt_DD
   101        Move itemID to Invt.Item_id
   102        Send Find of Invt_DD eq 1
   103        If (Not(Found)) Begin
   104            //If the inventory item cannot be found, we raise a web service exception
   105            Send WebServiceException ("Unknown inventory item '"+itemID+"'")
   106            Function_Return
   107        End
   108        Function_Return Invt.Unit_price
   109    End_Function
   110
   111    { Published = True  }
   112    { Description = "Looks up an order and returns the delivery date. Example customer number 1 and order number 101."  }
   113    Function EstimatedOrderDeliveryDate Integer customerNumber Integer orderNumber Returns Date
   114        Send Clear of OrderHea_DD
   115        Move customerNumber to OrderHea.Customer_number
   116        Move orderNumber to OrderHea.Order_number
   117        Send Find of OrderHea_DD eq 2
   118        If (Not(Found)) Begin
   119            //If the order cannot be found, we raise a web service exception
   120            Send WebServiceException "The specified order number, or order number/customer number combination, is invalid"
   121            Function_Return
   122        End
   123
   124        //We don't actually have a delivery date field in the database
   125        //so we'll simply use the order date for this sample and add 30 days to it
   126        Function_Return (OrderHea.Order_date + 30)
   127    End_Function
   128
   129    { Published = True  }
   130    { Description = "Calculates the total number of items sold. Example item identifiers, DT, GOLD, MAPS, OBM, RUNMTR."  }
   131    Function ItemsSoldToDate String itemID Returns Integer
   132        Integer total
   133        //We'll do a simple brute force search through the database
   134        //and calculate the total number of items sold.
   135        //It's a bit naive, but it will do for this example
   136        Send Clear of OrderDtl_DD
   137        Send Find of OrderDtl_DD ge 1
   138        While (Found)
   139            If (OrderDtl.Item_id = Uppercase(itemId));
   140                Increment total
   141            Send Find of OrderDtl_DD gt 1
   142        Loop
   143        Function_Return total
   144    End_Function
   145
   146End_Object    // oTestService
   147