Custom Data service providers-(7) Interactive Query

Source: Internet
Author: User

For the complete tutorial directory, see :《CustomData service providers-Introduction"

 

Whenever I write a plug-in and connect it to the framework system, I always think: How does the framework system call my plug-in?

I am used to this mode of thinking, which simplifies my understanding of how it works.

In factDSPIn the development process, I also use this method to understandDataservice.

I will usePseudoCodeTo describe theseDSPHow the interface is called.

Scenario - Basic Query

Think about it. A client initiatesGetRequest, for example:/Sample. svc/products (1).

FirstData Services.

//Get service provider

VaR dataservice = ...;

Iserviceprovider sp = dataservice as iserviceprovider;

If (sp = NULL)

{

//Add the code here later!!!

}

 

//ObtainDSPImplementation of each interface

Idataservicemetadataprovider MDP =

Sp. getservice (typeof (idataservicemetadataprovider ));

Idataservicequeryprovider QP =

Sp. getservice (typeof (idataservicequeryprovider ));

 

//Assign values if necessaryCurrentdatasourceAttribute

If (QP. currentdatasource = NULL)

QP. currentdatasource = dataservice. createdataservice ();

 

//Try to get the nameProductsResource set

VaR resourceset = NULL;

If (! MDP. tryresolveresourceset ("products", out resourceset ))

Throw new exception ("404 ");

 

//Obtain a resource setProductsObject (Queryable)

Iqueryable queryroot = QP. getqueryrootforresourceset (resourceset );

 

//UseURL(For example$ Filter/$ select) Merges existing query objects into new Query expressions.

Queryroot = compose (options, queryroot );

 

//Write the "Header" part of the reply

Writestartodatafeed ();

 

//Enumerate all query results

Foreach (Object resource in queryroot)

{

//Obtain the type of the resource.

//The type in the result set may be the derived type of the basic type, resulting in different instance types.

Resourcetype type = QP. getresourcetype (type );

Writeresource (resource, type );

}

Writeendodatafeed ();

I hope this pseudocode can help you understandDSPInData ServiceHow the framework works.

Next step

In the next tutorial, We will temporarily leave this query model and begin to implement service operations and query interceptors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.