The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Setup guild for winForm and WCF service

Last post 09-08-2008, 9:57 AM by Morak. 6 replies.
Sort Posts: Previous Next
  •  08-27-2008, 5:20 PM 10983

    Setup guild for winForm and WCF service

    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;

     

     

     

     

     

  •  08-28-2008, 5:09 PM 11023 in reply to 10983

    Re: Setup guild for winForm and WCF service

    This is totally awesome. Thanks. We will probably make a FAQ out this. Thank you so much for posting this. There has really been a lot of positive energy on the forums lately.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-02-2008, 2:02 PM 11097 in reply to 11023

    Re: Setup guild for winForm and WCF service

    I’m having issue with the proxy when I attempt to pass an ES Collection as a parameter to the service.  The proxy coverts the collection in the parameter to an object and the code breaks on the client.

     

    When you can share the library containing the generated classes with my client and service should you skip the proxy?  It was suggest that I write a ServiceHost and ChannelFactory instead of using the proxy generated by the wizard to avoid the type conversions in the proxy.  I would love to hear some thoughts on the best method to call a web method using ES when you can share the library with the service and the client.

     

    Jeff

  •  09-02-2008, 3:56 PM 11101 in reply to 11097

    Re: Setup guild for winForm and WCF service

    Look at this POST and notice how I use a "string" to pass data back and forth. This post shows step-by-step everything, and though it's for WebServices it's the same for WCF really. Of course, this is only useful when you are on both sides of the WCF conversation.

    Here's the issue, if you let visual studio synthesize objects for you to use on the client side those objects aren't you're ES objects or proxies, this would be true of a web service. However, you could post your code to that loads the data on the server and the code on the client that tries to consume it and then I would know more. But I suspect that is what is happening here.

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  09-03-2008, 10:17 AM 11141 in reply to 11101

    Re: Setup guild for winForm and WCF service

    The code I was using is posted above, and I agree that VS is using its own proxy when I used the wizard code to create a web reference in the client.  I read the post you mentioned but is assumes you have a web service and client configured.   It looks like I need to use the instructions for the XmlProxy Webservice (and WCF).

     

     

    Set up questions

    1) What ES Classes should I use (Template Browser>Zeus Teplates by Namespace>EntitySpaces 2008>C#>Generated Classes or Template Browser>Zeus Teplates by Namespace>EntitySpaces 2008>C#>ProxyStub>ProxyStub=Client Side (C#)

     

    2) Should I use the default setting when generating the ES classes? If not what options do I need to change?

  •  09-04-2008, 3:37 PM 11177 in reply to 11141

    Re: Setup guild for winForm and WCF service

    I have the channel factory working with the basic GetData method however when I try to returns a collection I get the following error.

     

    An unhandled exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll

     

    Additional information: The underlying connection was closed: The connection was closed unexpectedly.

     

    Client Code:

    public Form1()

            {

                InitializeComponent();

    EndpointAddress Address = new EndpointAddress("http://localhost:1099/Service1.svc");

                BasicHttpBinding binding = new BasicHttpBinding();

                IChannelFactory<IService1> channelFactory =

                    new ChannelFactory<IService1>(binding);

                IService1 proxy = channelFactory.CreateChannel(Address);

                Console.WriteLine("The Number is " + proxy.GetData(1));

                //MessageBox.Show(proxy.GetData(1));

                VwSelectionDataCollection coll = new VwSelectionDataCollection();

                coll = proxy.GetSelectionData();

                dataGridView1.DataSource = coll;

            }

     

     

    Service Code:

     

     

    public class Service1 : IService1

        {

            public string GetData(int value)

            {

                return string.Format("You entered: {0}",  value);          

            }

     

            public VwSelectionDataCollection GetSelectionData()

            {

    VwSelectionDataCollection coll = new VwSelectionDataCollection();

                coll.Query.Load();

                return coll;                        

            }

        }

     

    Any help would be great,

    Jeff

  •  09-08-2008, 9:57 AM 11231 in reply to 11177

    Re: Setup guild for winForm and WCF service

    Need a little help with syntax.  I’ passing a proxy to my client but I’m not sure how to covert the proxy back to a collection.

     

     

View as RSS news feed in XML