I wrote the following instructions to as a step by step guild to setting up WinForm client and a WCF service. I recommend that you first follow the “EntitySpaces- Getting Started” guild in the documentation and then create a new project to set WCF service. You will need to modify some of the expel code based on the name of the classed created my Mygeneration but the rest of the instructions should be apply. I would like to thank Jon Davis for his EntitySpaces and Silverlight Demo in which this guild is based on.
Setting up a EntitySpaces project using WCF and Winforms.
(I’m using VS Team System 2008.
1) Create solutions and project
a. Open Visual Studio
b. Build the Client
i. Select File>New>Project
ii. Select Project types>Visual C#>Windows>Windows Form Application
iii. Rename the project “Client”
iv. Rename the Solution: “ES_WCF_Demo”
v. Select OK
c. Build Class library
i. Right click the solution in the solution Explorer
ii. Select Add>New Project
iii. Select Project types>Visual C#>Windows>Class Library
iv. Rename the Project : ESData
v. Select OK
d. Build WCF Service
i. Right click the solution in the solution Explorer
ii. Select Add>New Project
iii. Select Project types>Visual C#>Web>WCF Service Application
iv. Rename the Project: WCFService
v. Select OK
2) Create EntitySpaces Classes
a. Create Generated File
i. Open Mygeneration
ii. Set up your database connection using the Getting Started Guild
iii. Right Click Template Browser>Zeus Teplates by Namespace>EntitySpaces 2008>C#>Generated Classes
iv. Select Execute
v. Select the tables/ views in the basic information Tab as you did in the Getting Started Guild
vi. Select Path and set the path to …\ES_WCF_Demo\ESData\Generated
vii. Change the NameSpace to reflect your data (SelectionData)
viii. Unselect “Metadata Class Should Ignore Schema” in the Advanced Options Tab
ix. Select “Generate the Proxy/Stub” and “Support WCF” in the Proxy/Stub Tab
x. Select OK
xi. Close MyGeneration
b. Include ES Files in Solution
i. Select ESDATA Project
ii. Select Show All Files from the Solution Explorer Toolbar
iii. Right click the “Generated” Folder
iv. Select Include In Project
3) Add References
a. Add ES Data References
i. Right click ESDATA>References>Add Reference
ii. Select Browse>c:/Program Files/EntitySpaces 2008/Runtimes/.Net 3.5
iii. Select EntitySpaces.Core and EntitySpaces.Interfaces
iv. Select Ok
v. Select System.Runtime.Serialization and System.ServiceModel from the .Net Tab
vi. Select OK
b. Add WCFServices References
i. Add the same References to WCFServices that you added to ESData
ii. Also add EntitySpaces.Loader EntitySpaces.LoaderMT EntitySpaces.SQLClientProvider, EntitySpaces.Web, EntitySpaces.Web.Design
iii. Add a Reference to the ESData Project
1. right click on the reference folder in the WCFService project
2. Select Add Reference
3. Select the Projects Tab
4. Select ESDATA
5. Select OK
4) Update Service
a. Update the WCFService Web.Config
i. Past the following into the Web.Config ConfigSections
<sectionGroup name="EntitySpaces" type="EntitySpaces.Interfaces.esConfigSettings, EntitySpaces.Core">
<section name="connectionInfo" type="EntitySpaces.Interfaces.esConfigSettings, EntitySpaces.Interfaces" allowLocation="true" allowDefinition="Everywhere" restartOnExternalChanges="true"/></sectionGroup>
ii. Past the following into the Web.Config configuration section and modify the connection string per the Getting Started Guild.
<EntitySpaces>
<connectionInfo default="SQL">
<connections>
<add name="SQL" providerMetadataKey="esDefault" sqlAccessType="DynamicSQL" provider="EntitySpaces.SqlClientProvider" providerClass="DataProvider" connectionString="---;Persist Security Info=True;User ID=---;Initial Catalog=---;Data Source=---" databaseVersion="2005"/>
</connections>
</connectionInfo>
</EntitySpaces>
b. Create Global.asax file
i. Right click on the WCFService project in the Solution Explorer
ii. Select Add>New Item
iii. Select Web>Global Application Class
iv. Select Add
v. Open the Global.asax file
vi. Update the Application_Start with the following:
protected void Application_Start(object sender, EventArgs e)
{
EntitySpaces.Interfaces.esProviderFactory.Factory = new EntitySpaces.LoaderMT.esDataProviderFactory();
}
c. Update Service Interface
i. Right click IService1.cs and select view Code
ii. Add the follwong code to public interfaces IService1
[OperationContract]
SelectionData.VwSelectionDataCollectionProxyStub GetSelection();
iii. Right click Service1.svc.cs and select view Code
iv. Add the following code to Public class Service1
public SelectionData.VwSelectionDataCollectionProxyStub GetSelection()
{
SelectionData.VwSelectionDataCollection coll = new SelectionData.VwSelectionDataCollection();
coll.Query.es.Top = 5;
coll.Query.Load();
SelectionData.VwSelectionDataCollectionProxyStub proxy = new SelectionData.VwSelectionDataCollectionProxyStub(coll);
return proxy;
}
5) Update Client
a. Build Service Reference
i. Right click on Solution and Select Build Solution
ii. Right click on the Reference folder in the Client project
iii. Select Add Service Reference
iv. Select Discover
v. Select the Service (Service1)
vi. Select OK
b. Update Form
i. Right click Form1.cs select View Designer
ii. Drag a DataGridView from the toolbar to the form
iii. Double click on the form to open the code behind
iv. Add “using Client.ServiceReference1” to the forms using statements;
v. Add the following code to Form1_Load:
Service1Client client = new Service1Client();
VwSelectionDataCollection coll = new VwSelectionDataCollection();
coll = client.GetSelection();
grdTestGrid.DataSource = coll.Collection;