Building a .NET Connectivity Assembly
You’ve seen how to connect to a business system using SharePoint Designer. The wizards make it simple to connect to SQL Server databases or appropriately designed WCF services. But what happens if you want to connect to something a bit more exotic? The answer is to create a .NET connectivity assembly. By creating a connectivity assembly, you can write code to handle any of the operation stereotypes supported by the BDC service. As mentioned earlier, BDC itself doesn’t read or write to the external data store; it simply delegates to an appropriate endpoint. By creating a connectivity assembly, you can effectively create custom endpoints to do whatever is appropriate for your application.
Pluggable Connector Framework
As briefly covered earlier in the section “Connector Framework,” BCS makes connections to external systems via a pluggable connector framework. It is therefore possible to create custom connectors to interface with external systems. While creating custom connectors is beyond the scope of this chapter, it’s worthwhile for you to know the differences between creating a custom connector and using a connectivity assembly.
Connectivity assemblies encapsulate an entire data access model. In the preceding section, we worked through configuring the metadata for the database connector; with connectivity assemblies, such configuration isn’t required since the metadata is installed with the connectivity assembly. Naturally, this lack of configurability can also be considered a drawback where the APIs for the external data store are likely to change frequently.
When you’re building custom connectors, you should be aware of some installation considerations. Connector assemblies must be manually installed in the Global Assembly Cache (GAC) on each server or rich client that intends to use the connector. By contrast, a connectivity assembly is stored within the BDC data store and is therefore automatically available to the BDC service on every server. Where the assembly is required by a rich-client interface, it is seamlessly installed via ClickOnce.
Business Data Connectivity Model Project
From our demonstration scenario, we require the functionality to attach product information retrieved from Internet search results to our competitive analysis reports. Of course, we could achieve this result by using a web browser and simply cutting and pasting the URL into a text field, but in the age of the mash-up, switching between applications in such a fashion would almost certainly lead to a disciplinary hearing of the International Association of Mash-up Artists—not to mention the fact that it would deprive us of the opportunity to explore Business Data Connectivity Model projects in Visual Studio 2010.
Create a New Project in Visual Studio 2010
To create a new Business Data Connectivity Model project, take the following steps:
The Visual Studio 2010 design surface for creating connectivity assemblies includes a number of specific tools. First, the entity view, shown in the middle of the page in Figure, lets you see all of the entities defined in your data source and the identifiers and methods defined on them. By clicking a method or identifier in the entity view, the BDC Method Details pane, shown below the entity view in the figure, is populated with details about the methods and identifiers defined in the entity. Finally, the upper-right pane in Figure is the BDC Explorer pane. This control presents a hierarchical view of your BDC model.
Figure:The Business Data Connectivity Model design surface
Create a Custom Entity Service Object
Before we jump into creating a new Entity Service object, it’s worth discussing what an Entity Service object is and how it relates to the rest of the items in our model. A BDC model project consists of three things:
To relate this back to the connection we made earlier via SharePoint Designer, the BDCM file contains the configuration details that we entered in the Operations Design View of the External Content Type. The Entity Service object is the equivalent of the ADO. NET provider for SQL Server and the Entity class represents a row of data.
Now that you have a clear understanding of the purpose of the Entity Service object, we can move on to add the code required to support our data source.
Define a Method to Support the Finder Stereotype
Our next step is to implement methods that will be called by BCS clients to interact with the data source. In our demonstration scenario, we need to be able to query the data source using a wildcard query and retrieve a single specific result.
First of all, let’s take a look at the query method. You’ll remember from earlier examples that the operation for retrieving a list of data is referenced using the Finder stereotype. We’ll start by creating a new method for this stereotype.
Define a Method to Support the SpecificFinder Stereotype With our Finder operation in place, the next thing we need to add is a SpecificFinder operation to allow clients to retrieve a single specific entity.
Now that we have the metadata in place for our model, we can start fleshing out our ReadList and ReadItem methods.
TIP The SharePoint server that’s used as the target for deployments can be changed by clicking the Project node in Solution Explorer and changing the Site URL property in the Properties pane.
Create a Custom Entity Object
One of the things you may notice when reviewing the properties of the WebResult External Content Type in SharePoint Designer is that no fields are defined. Of course, there is a perfectly reasonable explanation for this. If you look back at the return types for the ReadLst and ReadItem methods, you’ll see that they return values of type IEnumerable<string> and string, respectively. While this is a valid configuration, SharePoint Designer can’t break down a single string into multiple fields; therefore, no fields are shown.
This is where the Entity object comes into play. An Entity object, as you’ll remember, defines an individual row of data; it stores individual field data as properties. To show individual fields in SharePoint, we need to create an appropriate object.
Earlier in the chapter, we added a service reference to allow us to communicate with the Bing service. By examining the details of the service contract, we can determine what fields are returned from the service. From the Bing Web Service definition Language (WSDL), we see that the Search method returns an array of WebResult elements:<xsd:complexType name="WebResult"><xsd:sequence>
By creating an object with a property for each of these elements, we’ll be able to pass the results back to our client application without any loss of data. However, rather than create a new entity class from scratch, we can simply hook up our metadata to the object that was created automatically when we added the service reference. This eliminates the unnecessary step of reading the data from the proxy class into a custom entity class before passing it back to the client.
TIP Although we could jump straight in and change the return types of our ReadList and ReadItem methods, it’s always a good idea to make changes to the metadata first, since these changes areautomatically cascaded to the Entity Service. Following this procedure helps to eliminate mismatches in data types since the assembly won’t build if a type copied from the metadata model into the Entity Service code isn’t valid.
Select the WebResult Type Descriptor, and then in the Properties pane, change the Type Name.
Our project will now build correctly.
Define Entity Metadata Before we redeploy our assembly, we need to make another important change. Even though we’ve updated the metadata to use the WebResult object as our Entity class, we haven’t added metadata defining the properties of the WebResult object. We need to update the WebResult Type Descriptor with details of the fields on the object that we want to allow clients to use.
Once the solution has been deployed, we can see in SharePoint Designer that the fields are now available as expected. (You might need to press F5 to refresh the view to see the changes.) We can test our model by creating an External List from it. Follow the procedure discussed in the section “Create an External List.”
When navigating to your new list for the first time, you’ll notice that it’s empty. This is expected, because the ReadList method requires a query property. So how do you set the property? In External Lists, data source filters can be defined as part of the view. If you modify the default ReadList view, you’ll find a Data Source Filters section containing a text box to enter a parameter for our Search Filter. Type a search query in the Search Filter text box and save the view to see the results displayed in the list:
Share Point 2010 Related Interview Questions
|Web Services Interview Questions||XML Interview Questions|
|Share Point 2010 Interview Questions||ASP.NET Interview Questions|
|Share Point Administration Interview Questions||BizTalk Admin Interview Questions|
|Microsoft Office SharePoint Server (MOSS) Interview Questions||Biztalk Server Interview Questions|
|Asp Dot Net Mvc 4 Interview Questions||Biztalk Esb Toolkit Interview Questions|
|InfoPath Interview Questions|
Share Point 2010 Tutorial
The Microsoft Sharepoint 2010 Platform
Developing With Sharepoint 2010
Presentation Layer Overview
Client Object Model
Infopath Forms Services
Enterprise Content Management
User Interface Customization
Application Services Overview
Service Application Framework
Word Automation Services
Data Access Overview
Linq To Sharepoint And Spmetal
Business Connectivity Services
User Profiles And Social Data
Packaging And Deployment Model
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.