IT tutorials
 
Technology
 

Sharepoint 2010 : Building a .NET Connectivity Assembly (part 3) - Define a Method to Support the SpecificFinder Stereotype

2/19/2014 3:32:33 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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.

  1. Follow steps 2 and 3 above to add a new method, but this time select Create a SpecificFinder in the BDC Method Details pane. By default, the new method will be named ReadItem.

  2. Since this method returns only a single item, we don’t need to create any filters. However, we do need to add a parameter that will uniquely identify the item to be returned. Since the results will consist of web pages, the most sensible identifier is the URL. Follow steps 4 and 5 above to add a new parameter named itemUrl.

  3. A new Type Descriptor of itemUrlTypeDescriptor is added. For the sake of brevity. rename this as itemUrl using the BDC Explorer:

  4. Before we move on to add the code to support these new methods, we need to add one more piece of metadata to the model: we need to declare our identifier. Right-click the WebResult entity and select Add | Identifier, as shown next. Change the default name to itemUrl.

  5. With this identifier created, we can now update the metadata for the itemUrl descriptor that we’re using to define the parameter for the ReadItem method. In the BDC Explorer pane, select the itemUrl type descriptor (ReadItem | itemUrl | itemUrl), and then, in the Properties pane, change the Identifier property to itemUrl.

Now that we have the metadata in place for our model, we can start fleshing out our ReadList and ReadItem methods.

  1. Save the BDC model, and then switch to the Solution Explorer pane in Visual Studio. You’ll notice that a WebResultService.cs file has been added. Open this file, and you can see that as we’ve been making changes to the model, Visual Studio has automatically created stub methods with the appropriate parameters for us. Since we don’t need them, delete the Entity1.cs and Entity1Service.cs files that were added to the project by default.

  2. In the WebResultService class, add the following code:

    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceModel.Channels;
    using System.ServiceModel;
    using BingConnectivity.Microsoft.Bing;

    namespace BingConnectivity.BdcModel1
    {
    public partial class WebResultService
    {
    public static IEnumerable<string> ReadList(string query)
    {
    //We can't perform a web search with no query
    if (!string.IsNullOrEmpty(query))
    {
    //Get an instance of the Bing proxy class
    BingPortTypeClient client;
    SearchRequest request = GetRequestProxy(out client);

    //Setup the request parameters
    request.Query = query;

    //Execute the search
    SearchResponse response = client.Search(request);

    //Shape the results to suit our requirements
    var results = from r in response.Web.Results
    select r.Url;

    return results;
    }
    else
    {
    return null;
    }

    }

    public static string ReadItem(string itemUrl)
    {
    if (!string.IsNullOrEmpty(itemUrl))
    {
    BingPortTypeClient client;
    SearchRequest request = GetRequestProxy(out client);
    request.Query = itemUrl;

    SearchResponse response = client.Search(request);

    //Since urls are globally unique this query will
    //only return one result
    return response.Web.Results.Single().Url;
    }
    else
    {
    return null;
    }

    }

    private static SearchRequest GetRequestProxy(out
    BingPortTypeClient client)
    {
    //When we added the service reference. Visual Studio automatically
    //added configuration information to app.config.
    //However since this assembly may be called from a number of processes
    //app.config won't be available. As a result we need to manually
    //configure the service.

    Binding b = new BasicHttpBinding();
    EndpointAddress address = new
    EndpointAddress("http://api.bing.net:80/soap.asmx");

    client = new BingPortTypeClient(b, address);

    SearchRequest request = new Microsoft.Bing.SearchRequest();

    request.AppId = "ENTER YOUR APPID HERE";

    //We're only interested in search the Web source
    //See Bing SDK for more details on this parameter

    request.Sources = new SourceType[] { SourceType.Web };

    return request;
    }

    }
    }


  3. With the methods fleshed out, we can now build and deploy the model to SharePoint to see the results of our actions. Choose Build | Deploy BingConnectivity. The project will be built, packaged, and automatically installed on the SharePoint server that we specified when creating the project.

  4. In SharePoint Designer, navigate to the External Content Types explorer. You can see that a new WebResult content type has been added with type .Net Assembly. By opening the content type, you can see whether the metadata configuration is as expected and the appropriate operations have been added.

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.

 
Others
 
- Sharepoint 2010 : Building a .NET Connectivity Assembly (part 2) - Create a Custom Entity Service Object, Define a Method to Support the Finder Stereotype
- Sharepoint 2010 : Building a .NET Connectivity Assembly (part 1) - Business Data Connectivity Model Project
- Windows 8 : Configuring security - Managing Windows Firewall and exceptions (part 5) - Configuring outbound rules, Configuring connection security rules
- Windows 8 : Configuring security - Managing Windows Firewall and exceptions (part 4) - Allowing the secure connection
- Windows 8 : Configuring security - Managing Windows Firewall and exceptions (part 3) - Configuring IPsec settings
- Windows 8 : Configuring security - Managing Windows Firewall and exceptions (part 2) - Modifying a firewall profile
- Windows 8 : Configuring security - Managing Windows Firewall and exceptions (part 1) - Choosing Windows Firewall
- Exchange Server 2010 : Interoperability with Earlier Versions of Exchange
- Exchange Server 2010 : Positioning the Client Access Server in Your LAN (part 2) - Client Redirection, Client Access Arrays
- Exchange Server 2010 : Positioning the Client Access Server in Your LAN (part 1) - Client Access Server Proxying
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us