Yes, yes, the Master Data Hub makes creating a new member simple and straight-forward, but if you are a developer like me, you want to dive into the WCF services and write some code. Right? Right.
There are some good resources on the topic out there for creating your first integration project in Visual Studio.
I wanted to take this a step further and actually create a customer member in the Customer sample model.
First, I created a simple screen for connecting to the .svc endpoint – simply did not want to hard code the value.
The code for setting up the endpoint is the same for other WCF clients. The important piece is the location of the .svc file, which is located under the MDS site you created in Configuration Manager, under service/service.svc.
Note: the service has a ServiceCheck method which effectively pings the service to ensure we are up and running.
OK, you have your service client now. Let’s create a new Customer. The Customer model has a few Required Attributes – what this means is that the member will fail to validate when the business rules are run against it: however, you can still add the member. All you need, in fact, is a code (you don’t even need a name). That said, in this example, I choose to provide the capability to set Code, Name, Address and Customer Status from a single call to the service.
First step is our using statements. I like to shorten the long namespace. Also, we will use Collections throughout.
Next, let’s get the model and entity to which we want to add the new member. We can do this by using the MetadataGet method on our ServiceClient object. There are a few things to note here:
1. The ResultType enumeration allows us to limit the result set to just the identifiers for these objects. We only need the identifiers for Model, Entity and Version.
2. The SearchOption enumeration allows us to limit our search to User Defined objects
3. We find the Model and Entity by name. There is only “VERSION_1” currently, but this would be a good thing to add later.
If we did this right, we should now have only one model, entity and version each:
Now, we need to collect in the information entered by the user on the screen and construct our new member and attributes. This is somewhat painstaking, but it allows us to make one big call to the service endpoint, rather than a set of calls in sequence.
Additional Attributes have been elided for brevity.
Finally, we add the attributes to the Member object, transform the Member object into an EntityMember object (using our criteria from earlier) and submit the data.
I’m looking forward to trying this approach from InfoPath clients, SharePoint web parts and with BizTalk Server.