In this sample you will use a regular expression to search for a particular
pattern in the return value of a Web method call. The Web method will
be used as a target and will simulate adding Orders to a system.
There are two business rules enforced by the Web Method:
The Customer ID must be equal to CUST001.
The Tax Rate must be greater than 0.
If both of those conditions are met, the method will return an XML message
indicating success. If one of those conditions is not met, the method
will return an XML message indicating failure. Note that this Web Method,
unlike the Logon method, does not throw an exception, but returns a string
indicating pass/fail.
A sample ReturnValue would look like the following if neither rule was
successful (assuming the OrderID is '1'):
<Results
OrderID="1" Status="Failed">
<ValidationError Rule="Invalid CustomerId">CustomerID not recognized.</ValidationError>
ValidationError Rule="Invalid Tax Rate">The
Tax Rate must be greater than 0.</ValidationError>
</Results>
Notice that each invalid rule is listed as its own ValidationError node.
The Status attribute equals either Passed or Failed.
For our example, we are going to look for the Status
equal to Failed and, if that is
true, fail the target operation.
Note: Although the target operation
fails, the Adapter for Web Services does not roll back anything. Therefore,
it is possible for the Web method in question to be working while
the target operation fails.
Example
In the Scribe Workbench,
click View > Connections. The Connection Manager appears.
Click New. The Add a Connection dialog box appears.
Expand Adapters.
Click Web
Services.
Click OK. The Web Services Connection Manager dialog box appears.
In the Methods
list, select the SaveOrder method,
and then select the ReturnValue
parameter.
Note: In this example,
the ReturnValue is an XML document similar to the above example. You assign a regular expression with this parameter.
In the Value
box, enter %ReturnValue .
In the Failure Condition box
enter Status="Failed".
Be sure to include the quotes.
Click Save. You return to the Web Services Connection Manager dialog box.
Select the Web Service connection
you just edited and click Connect. The Login To Web Service Window appears.
Click OK. The Connection Settings dialog box appears.
Click OK. The Connection Manager
On the Connection
Manager, click Close.
run a DTS file to catch the non-SOAP exception
In the Scribe Workbench, on the
Target menu, click Configure Steps. The Configure Steps dialog box appears.
From the drop-down list of connections, select the
connection that represents the Web Service.
Expand Adapter
Objects and select SaveOrder.
Click Add
Execute Step.
Click Close. The Configure Steps window closes.
Set up a connection to the
Scribe Sample database and configure it as your source, using ORDER_HEADER
as the source table.
Create the following mappings:
Create a data link between the ORDERHEADERID
field from the source and the Ord_OrderID
field from the target.
Use a formula to create the static value "TESTCUST"
for the Ord_CustomerID field from
the target.
To create this formula, select Ord_CustomerID,
and click Formula. Enter "TESTCUST" in the formula
window and click OK. Be sure to include the quotation marks. "TESTCUST"
appears in the Data Formulas tab next to Ord_CustomerID.
Use a formula to create the static value -100
for the Ord_TaxRate field from
the target.
Save and run the DTS file.
All rows display
as having failed the target operation. The Transaction
ErrorsReport indicates the failure occurred because the ReturnValue satisfied the
regular expression we supplied.
Do the following mappings to resolve the error:
Modify the formula on the Ord_CustomerID
target field to use a static value of "CUST001".
Modify the formula on the Ord_TaxRate target field to use a number greater than 0.
Note: With these values, no validation errors occur and the XML returned
has Status="Passed", whici does not satisfy the
regular expression we have defined above.