Custom Data service providers-(5) Minimal runtime Service

Source: Internet
Author: User

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

 

 

In the previous tutorial, we have implementedIserviceproviderAndIdataservicemetadataprovider, Now let's continue.

Mount Idataservicequeryprovider Implementation

Now we plan to implementIdataservicequeryproviderInterface, We Need To refactor the previously implementedIserviceproviderInterface.

Public abstract class dspdataservice <t>:

Dataservice <t>, iserviceprovider

{

Public idataservicemetadataprovider _ metadata;

Public idataservicequeryprovider _ query;

 

Public dspdataservice ()

{

_ Metadata = getmetadataprovider (typeof (t ));

_ Query = getqueryprovider (_ metadata );

}

Public object getservice (type servicetype)

{

If (servicetype = typeof (idataservicemetadataprovider ))

Return _ metadata;

Else if (servicetype = typeof (idataservicequeryprovider ))

Return _ query;

Else

Return NULL;

}

 

Public abstract idataservicemetadataprovider

Getmetadataprovider (type datasourcetype );

 

Public abstract idataservicequeryprovider

Getqueryprovider (idataservicemetadataprovider metadata );

}

Note: You need to implement it in your own implementation class.GetqueryproviderMethod.

IdataservicequeryproverImplementation may requireIdataservicemetadataproviderSo this parameter is passed in.

Public class sample: dspdataservice <Object>

{

...SeeCode...

 

Public override idataservicequeryprovider

Getqueryprovider (idataservicemetadataprovider metadata)

{

Return new dspqueryprovider <Object> ();

}

}

Implementation Idataservicequeryprovider

If you only want to see the service contract and$ MetadataInformation, then implementCurrentdatasourceAttribute. Other methods of this interface are returned after the query is called.Resourcesets.

Public class dspqueryprovider <t>: idataservicequeryprovider

{

T_currentdatasource;

Public object currentdatasource

{

Get {

Return _ currentdatasource;

}

Set {

_ Currentdatasource = value as t;

}

}

Public object getopenpropertyvalue (

Object target,

 String propertyname)

{

Throw new notimplementedexception ();

}

Public ienumerable <keyvaluepair <string, Object>

Getopenpropertyvalues (object target)

{

Throw new notimplementedexception ();

}

Public object getpropertyvalue (

Object target,

Resourceproperty)

{

Throw new notimplementedexception ();

}

Public iqueryable getqueryrootforresourceset (

Resourceset)

{

Throw new notimplementedexception ();

}

Public resourcetype getresourcetype (object target)

{

Throw new notimplementedexception ();

}

Public object invokeserviceoperation (

Serviceoperation,

Object [] parameters)

{

Throw new notimplementedexception ();

}

Public bool isnullpropagationrequired

{

Get {Throw new notimplementedexception ();}

}

}

 

Well, at least our custom data service provider can now run, although it can only provide metadata information.

In the browser, type:Http: // localhost/sample. SVCNow you can see the following picture:

Note: InVisual StudioIn the debugging environment,LocalhostA dynamic port is required later)

 

If you typeHttp: // localhost/sample. svc/$ metadataYou should see the following picture:

 

Of course, we have not implemented the query. If you want to navigateProductsIf the resource set is used, an error is returned (the address is:Http: // localhost/sample. svc/products

 

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.