Share via


How to: Specify a Default Value for a Parameter of Type System.DateTime

Some methods have complex signatures. For example, the Web service to get SAP customers might take six parameters, three of which might be structures with subparameters. To make it easier for users to call these methods, the Business Data Catalog enables you to specify default values for parameters in the metadata. This way, users can invoke predefined business logic without undertaking parameter construction.

The user can override any input parameter for which you define a DefaultValue. The user must specify any input parameter that has no DefaultValue, if the parameter is not optional.

For each abstract primitive in a TypeDescriptor object, you can define multiple default values, each of which corresponds to a particular MethodInstance object. At run time, depending on which MethodInstance object the client executes, an instance of the parameter is created based on the corresponding default values.

The topic DefaultValue lists the accepted formats for providing default values for different types. As mentioned in that topic, to provide default values for Web methods that have input parameters of type System.DateTime, you need to pass in the value as a string in the DateTimeFormatInfo.UniversalSortableDateTimePattern format. The following code is an example.

Note

If you use an incorrect DateTime format in the default value, you get an error when you import the application definition file: Could not parse Default Value into Type 'System.DateTime'. Ensure that the format is correct and do not use quotation marks around the value.

Example

<DefaultValues>
    <DefaultValue MethodInstanceName="InvoiceFinderInstance" 
       Type="System.DateTime">2007-01-11 00:00:00Z
    </DefaultValue>
</DefaultValues>