Master Data Services Entity Based Staging API Sample
This is a C# code sample to show how to process, clear, and get information about entity based staging data by using MDS APIs. This sample has the following scenarios.
- Process the staging data in the staging table that has the specified batch tag (“Test1”). After calling the API to process the staging data wait untill the batch process completes (wait for 60 seconds).
- Get the staging information such as the batch status and the error information. In this example, GetStagingInformation method returns the batch id for the specified batch tag.
- Clear the batch staging data for the specified batch id.
- Create a new business rule to validate the record that is added by Entity Based Staging and get the validation error.
Before running this sample code you need to populate the staging table for the entity that you use with a staging record. The staging record should have batch tag = "Test1". Example: Populate the record into stg.TestEntity_Leaf staging table with batch tag = “Test1” by running the SQL script. Note that the Code and Name below is set to trigger the business rule validation error (if Code is “ABC”, Name must be equal to “Test”). Insert into stg.TestEntity_Leaf (ImportType, BatchTag, Code, Name) values (0, N'Test1', N'ABC', N'Name2'); ImportType = 0 means the import type is merge optimistic.
Please set the MDS URL (plus /Service/Service.svc) to mdsURL in Program.cs. string mdsURL = @"http://localhost/MDS/Service/Service.svc";
Program.cs uses Reference.cs (the service reference class file) that was generated by using Visual Studio to access MDS Web service API. You may need to regenerate Reference.cs in case when MDS Web service API is changed.
To generate Reference.cs using Visual Studio: You need to expose the WSDL. Exposing the WSDL is only necessary at the time when you want to generate proxy classes using a client development tool such as Visual Studio. After a proxy has been generated, the WSDL does not need to be exposed going forward for client programs to call the API.
To enable an http/https Get on the WSDL:
- Open the MDS web.config file in a text editor (\Microsoft SQL Server\Master Data Services\WebApplication\web.config).
- Search for the tag serviceMetadata and set httpGetEnabled to true (or httpsGetEnabled if using SSL).
To also enable service exception details for additional debugging (not necessary for standard, trapped errors):
- Search for the tag ‘serviceDebug’ and set includeExceptionDetailInFaults to true.
After that you need to add a Service Reference to http:////service/service.svc and set the namespace to the service to "MDSTestService" in the following steps using Visual Studio. 1. Click "Add Service Reference". 2. In Address, enter the URL to the MDS service which will be “http:////service/service.svc”. 3. Specify the namespace to the service as "MDSTestService" in the Namespace box. 4. Click the Advanced button to configure advanced settings. 5. Check Always generate message contracts. 6. Set the Collection type drop-down to System.Collections.ObjectModel.Collection. 7. Click OK to return to the Add Service Reference dialog. 8. Click OK.
Reference.cs will be generated in EntityBasedStaging\Service References\MDSTestService folder. You can replace EntityBasedStaging\Reference.cs with the newly generated one.