使用SQL Server 2008 R2的主數(shù)據(jù)服務(wù)調(diào)用API創(chuàng)建Model
SQL Server 2008 R2的主數(shù)據(jù)服務(wù)(Master Data Services,簡稱MDS)可以調(diào)用應(yīng)用程序接口API來創(chuàng)建Model,本文我們就介紹了這一創(chuàng)建的過程,需要說明的是首先需要啟用MDS當(dāng)中的Web Service服務(wù),啟動方法可以參考這篇文章:如何啟用Master Data Services的Web服務(wù)。接下來我們就開始介紹這一過程。
添加服務(wù)引用
在解決方案資源管理器窗口中,右鍵單擊引用,單擊添加服務(wù)引用;在地址,輸入的 URL 的 MDS 服務(wù)將"http:// <ServerName> / <MdsSiteName> / service/service.svc"。如果MDS 位于的計算機上執(zhí)行此操作,可以使用"localhost"作為服務(wù)器名稱;單擊繼續(xù)。Visual Studio 會嘗試獲取服務(wù)并檢索 WSDL;如果成功,將看到服務(wù)和IService在服務(wù)框中;該服務(wù)的Namespace框中指定命名空間。
在此示例中,我將其命名為MDService;單擊高級按鈕,可以配置高級的設(shè)置;勾選Always generate message contracts(不確定中文版翻譯成什么);設(shè)置集合類型下拉到System.Collections.ObjectModel.Collection;單擊確定返回到添加服務(wù)引用對話框。
通過API創(chuàng)建模型
- private static ServiceClient mdsProxy;
- protected void Page_Load(object sender, EventArgs e)
- {
- try
- {
- mdsProxy = CreateMdsProxy("http://devserver:8080/Service/Service.svc");
- }
- catch (Exception ex)
- {
- Response.Redirect("Error connecting:" + ex.Message);
- }
- }
- private static ServiceClient CreateMdsProxy(string mdsURL)
- {
- System.ServiceModel.EndpointAddress endptAddress = new System.ServiceModel.EndpointAddress(mdsURL);
- System.ServiceModel.WSHttpBinding wsBinding = new System.ServiceModel.WSHttpBinding();
- return new ServiceClient(wsBinding, endptAddress);
- }
- private void CreateModel(string newModelName)
- {
- MetadataCreateRequest request = new MetadataCreateRequest();
- MetadataCreateResponse response = new MetadataCreateResponse();
- request.Metadata = new Metadata();
- request.Metadata.Models = new System.Collections.ObjectModel.Collection<Model>() { new Model() };
- request.Metadata.Models[0].Identifier = new Identifier();
- request.Metadata.Models[0].Identifier.Name = newModelName;
- response = mdsProxy.MetadataCreate(request);
- }
- protected void btnCreateModel_Click(object sender, EventArgs e)
- {
- CreateModel("TestModel");
- }
- }
注意:MDS的站點有緩存機制,如果你之前已經(jīng)打開了該站點,則刷新之后不會看到新添加的那個Model,需要關(guān)閉瀏覽器或清理緩存。
關(guān)于使用SQL Server 2008 R2的主數(shù)據(jù)服務(wù)MDS調(diào)用API創(chuàng)建Model的過程就介紹到這里了,希望本次的介紹能夠帶給您一些收獲吧!
【編輯推薦】


2010-11-26 14:08:00
2010-11-26 14:11:33
2010-12-20 15:59:59




