Simple Tutorial: Host a WCF Service in the Sandbox

Discussion in 'ASP.NET 4.5 Beta [Closed]' started by daveswebcom, Mar 23, 2012.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. This is based on the tutorial at http://community.discountasp.net/showthread.php?t=7719&highlight=EvalService
    which, in my opinion, is WAY too complicated.

    Here are all the steps you need to take to host a WCF service in the ASP.Net 4.5 Sandbox. (Yes, you must first get a sandbox account, username and password). I've used the Visual Studio 11 Beta, but this should be fairly similar in VS2010.

    1. Open VS2011.
    a. Select: File->New->Project
    b. At the top of the "New Project" dialog, make sure ".NET Framework 4.5" is selected.
    c. Select: Project types="Visual C#"->"WCF" (or "Visual Basic" -> "WCF")
    d. Select: Templates="WCF ServiceLibrary"
    e. Set: Name="TestWcfServiceLibrary"
    f. CheckBox: Create directory for solution=true
    h. Set: Solution Name="TestWcfServiceLibrary"
    i. Select: "OK"

    2. In the main menu
    a. Select "File"->"Add New Web Site"
    b. Select Template="WCF Service"
    c. Set Filename=[ANYWHEREYOUWANT]
    d. Set Language="Visual C#" (or Visual Basic)
    e. Click "OK"
    f. Build the solution

    3. Open up FTP or Windows explorer
    a. login to the sandbox site (netfx45lab.discountasp.net -- the server will navigate to the proper folder based on your login)
    b. Copy Drag and drop the files in [ANYWHEREYOUWANT] to your base FTP directory.
    c. Verify with a web browser pointed to "http://YOURSANDBOXUSERNAMEHERE.netfx45lab.discountasp.net/Service.svc"

    4. Access the service with a simple Windows app
    a. Open VS (any version)
    b. On the File menu, click Add, then New Project
    c. In the New Project dialog, expand the Visual C# node and select Windows Forms Application.
    d. Give the project any name you want.
    e. Click "OK" to create the project.
    f. In Solution Explorer, Right-click your project and click "Add Service Reference"
    g. In the Address field, enter "http://YOURSANDBOXUSERNAMEHERE.netfx45lab.discountasp.net/Service.svc"
    h. Click "Go"
    i. Click "OK"
    j. Double-click Form1 to open it in the designer
    k. Add two text boxes and one button. By default, they will be named button1 textBox1 and textBox2
    l. Double-click the button and in the button1_Click event handler, add the following code:
    ServiceReference1.ServiceClient client = new ServiceReference.ServiceClient();
    textBox2.Text = client.GetData(System.Int32.Parse(textBox1.Text));
    m. Run your project.
    n. Enter an integer in textBox1
    o. Click the button
    p. You'll see the service response in textBox2

    That's all there is to it.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page