.netTiers
Help Wanted! If you are using .netTiers and find it as invaluable as we do, please consider giving back to the .netTiers team by helping with our effort to fully document .netTiers. To help, simply create an account and you will then be able to edit this wiki.

Edit

Web Services

.netTiers will allow you to create a Web Service provider which exposes your Data API. This is very beneficial if you need to use .netTiers in a client server application, or if you just need to expose your data to a 3rd party.

Edit

Configuring Generated Web Services

Once you've generated your solution, you will want to change your default provider on the client application. So this would be on the application that will be consuming web services. In the App/Web.config, you will want to change the default provider to WsNetTiersProvider in the netTiersServiceSection.

Edit

Configuration

In the web.config file of your application, add the following to define the <netTiersService> node. The <section> tag must be on one line.

1 <configuration> 2 <configSections> 3 <section name="netTiersService" 4 type="North.DataAccessLayer.Bases.NetTiersServiceSection, 5 North.DataAccessLayer" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/> 6 </configSections> 7 ... 8 </configuration>


Once the <netTiersService> has been defined, we add it to the web.config file. Note that its location is outside the <system.web> tag.

1 2 <netTiersService defaultProvider="WsNetTiersProvider"> 3 <providers> 4 <!--*** SqlClient Provider *** 5 connectionStringName: sqlclient connection string to the db 6 useStoredProcedure: if trueindicates that we use the stored procedures, otherwise, we use parametrized queries that are embedded. 7 --> 8 9 <add name="SqlNetTiersProvider" type="Northwind.Data.SqlClient.SqlNetTiersProvider, Northwind.Data.SqlClient" 10connectionStringName="netTiersConnectionString" useStoredProcedure="false" 11providerInvariantName="System.Data.SqlClient" entityFactoryType="Northwind.Entities.EntityFactory" enableEntityTracking="true" /> 12 13 <!-- 14 *** WebserviceClient Provider *** 15 The url parameter indicates the webservices url (ex: http://localhost/NorthWind/NorthWindServices.aspx) 16 --> 17 18 <add name="WsNetTiersProvider" type="Northwind.Data.WebServiceClient.WsNetTiersProvider, Northwind.Data.WebServiceClient" url="http://localhost/NorthwindServices/NorthwindServices.asmx" /> 19 </providers> 20 </netTiersService>


If you are building a Windows Forms application then you would put the following in the app.config...

1 <configSections> 2 <section name="netTiersService" type="Northwind.Data.Bases.NetTiersServiceSection, Northwind.Data" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/> 3 </configSections> 4 <netTiersService defaultProvider="WsNetTiersProvider"> 5 <providers> 6 <!-- 7 *** WebserviceClient Provider *** 8 The url parameter indicates the webservices url (ex: http://localhost/NorthWind/NorthWindServices.aspx) 9 --> 10 11 <add name="WsNetTiersProvider" type="Northwind.Data.WebServiceClient.WsNetTiersProvider, Northwind.Data.WebServiceClient" url="http://localhost/NorthwindServices/NorthwindServices.asmx" /> 12 </providers> 13 </netTiersService>


Edit

Using Web Service Provider

Now that you have a generated solution, the first thing you will want to do is perform a Build, Control + B . This build will fail, only because the WebService Client does not have an updated set of proxy classes for your Web Reference. We did the build however to create the actual WebService Project so that now it can be discoverable.

You can now browse to your web service and view all the of the exposed data API Methods:
Webservice Exposed API

Webservice Exposed API


Edit

Updating Web Reference

In your project browse to the Web Service Client project.
Updating Your Web Reference

Updating Your Web Reference


Then you simply have to update your web reference for the WsProxy by right clicking - Update Web Reference. Also, Please ensure that the Web Reference URL property is the correct Url mapping for your web services endpoint.

Updating Your Web Reference

Updating Your Web Reference


Once this has been updated, please do one more build, this time, there should be no compilation errors. If you still have errors, copy the DLLs from your entity and data bin/debug directories over to the service client bin/debug.

On the server, with the actual web service endpoint, you will notice, that it's web.config does indeed use the SqlNetTiersProvider. This is correct and should not be modified, because now you want to directly communicate with your SQL Database.

Edit

Updating Other References

If you are building a Windows Forms application then you will want to update that project's references to point to the Data, Entities, and WebServiceClient projects or dll's. In this example that would be "Northwind.Data", "Northwind.Entities", and "Northwind.Data.WebServiceClient".

Edit

Accessing your Data

Once you have completed the previous step, you are now free to use the client just as you would if you were using the SqlNetTiersProvider.

Example:

1 using Northwind.Data; 2 using Northwind.Entities; 3 using Northwind.Data.WebServiceClient; 4 5 TList<Orders> list = DataRepository.OrdersProvider.GetAll();


Will call EntityProviderBaseCore.cs :

1 2 /// <summary> 3 /// Gets all rows from the DataSource. 4 /// </summary> 5 /// <returns>Returns a TList of Entity objects.</returns> 6 public TList<Entity> GetAll() 7 { 8 return GetAll(null); 9 }


Will call WsOrdersProvider.generated.cs :

1 /// <summary> 2 /// Gets All rows from the DataSource. 3 /// </summary> 4 /// <param name="transactionManager"> object</param> 5 /// <param name="start">Row number at which to start reading.</param> 6 /// <param name="pageLength">Number of rows to return.</param> 7 /// <param name="count">out parameter to get total records </param> 8 /// <remarks></remarks> 9 /// <returns>Returns a TList<Northwind.Entities.Orders></returns> 10 public override Northwind.Entities.TList<Orders> GetAll( 11 TransactionManager transactionManager, 12 int start, 13 int pageLength, 14 out int count) 15 { 16 17 WsProxy.NorthwindServices proxy = new WsProxy.NorthwindServices(); 18 proxy.Url = this._url; 19 20 WsProxy.Orders[] items = 21 proxy.OrdersProvider_GetAll(start, pageLength, out count); 22 23 return Convert(items); 24 }


This calls the web service via the proxy class and returns your query. This will also convert the items back into a TList instead of returning an array of proxy Orders.

ScrewTurn Wiki version 2.0.31.