Master Data Services Metadata API Sample
This is a C# code sample to show how to use MDS APIs to create, read, update, and delete Metadata.
The sample code includes the following scenarios.
- Create, get information of, update, and delete a Model using MDS API.
- Create, get information of, update, and delete an Entity using MDS API.
- Create, get information of, update, and delete an Attribute using MDS API.
- Create, get information of, update, and delete an Attribute Group using MDS API.
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 the 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://ServerName/MdsSiteName/service/service.svc and set the namespace to the service to "MDSTestService" in the following steps using Visual Studio.
- Click "Add Service Reference".
- In Address, enter the URL to the MDS service which will be “http://ServerName/MdsSiteName/service/service.svc”.
- Specify the namespace to the service as "MDSTestService" in the Namespace box.
- Click the Advanced button to configure advanced settings.
- Check Always generate message contracts.
- Set the Collection type drop-down to System.Collections.ObjectModel.Collection.
- Click OK to return to the Add Service Reference dialog.
- Click OK.
Reference.cs will be generated in Metadata\Service References\MDSTestService folder. You can replace Metadata\Reference.cs with the newly generated one.