是否可以使用 Visual Studio Express for Windows Desktop 2013 开始探索 WCF? [英] Is it possible to start exploring WCF using Visual Studio Express for Windows Desktop 2013?

查看:40
本文介绍了是否可以使用 Visual Studio Express for Windows Desktop 2013 开始探索 WCF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否在 Visual Studio Express 2013 中为 Windows 桌面 C# 设置一个基本的 WCF 项目

Can you set up a bare bones WCF project in Visual Studio Express 2013 for Windows Desktop C#

MS 入门教程中描述的演练 (http://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx) 指的是 Visual Studio(不是速成版),它的模板不可用在 Visual Studio Express (WDExpress.exe) 中,特别是 WCF 服务库.

The walkthrough described in the MS Getting Started tutorial (http://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx) refers to Visual Studio (NOT the express edition), which has templates that are not available in Visual Studio Express (WDExpress.exe), specifically WCF Service Library.

如何在没有模板的情况下在 WDExpress.exe 中启动类似的操作?

How do you start something similar in WDExpress.exe without the templates?

顺便说一句,我曾尝试从 Visual Studio Express for Web 2013 (VWDExpress.exe) 复制模板,但没有成功.

Incidentally, I've tried copying templates over from Visual Studio Express for Web 2013 (VWDExpress.exe), but without success.

推荐答案

以下是 http://msdn.microsoft.com/en-us/library/bb386386.aspx 使用 Visual Studio Express 2013.

Here's a possible workaround for http://msdn.microsoft.com/en-us/library/bb386386.aspx using Visual Studio Express 2013.

所有步骤均在 VSE 2013 for Windows Desktop (WDExpress.exe) 中进行

All the steps are carried out in VSE 2013 for Windows Desktop (WDExpress.exe)

  • 步骤 1 - 使用 Class Library 的模板启动一个新项目 - 它应该生成一个默认名称为 ClassLibrary1

  • Step 1 - Start a new project using the template for Class Library - it should generate a project with the default name ClassLibrary1

第 2 步 - 转到 References(在 Solution Explorer 中)并添加对 System.ServiceModelSystem 的引用.Runtime.Serialization

Step 2 - Go to References (in Solution Explorer) and add references to System.ServiceModel and System.Runtime.Serialization

第 3 步 - 创建一个名为 WCFServiceLibrary1.cs 的新类,内容如下

Step 3 - Create a new class called WCFServiceLibrary1.cs with the following content

using System.ServiceModel;

namespace ClassLibrary1
{
    public class WCFServiceLibrary1 : IWCFServiceLibrary1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
}

  • 第 4 步 - 创建一个名为 IWCFServiceLibrary1.cs 的新类,内容如下
  • Step 4 - Create a new class called IWCFServiceLibrary1.cs with the following content

using System.ServiceModel;

namespace ClassLibrary1
{
    [ServiceContract] 
    public interface IWCFServiceLibrary1
    {
        [OperationContract]
        string GetData(string value);
    }
}

  • 第 5 步 - 您需要一个客户端来运行 WCF,因此创建一个 Windows 窗体,默认名称为 Form1.cs,并添加三个控件;一个文本框、(textBox1)、一个标签(label1)和一个按钮(button1)

  • Step 5 - You need a client to run the WCF, so create a Windows form, which will have the default name Form1.cs, and add three controls; a textBox, (textBox1), a label (label1), and a button (button1)

第 6 步 - 在 [设计] 模式下,双击 button1 并编辑动作,使 Form1.cs 看起来像这样

Step 6 - in [Design] mode, double click on button1 and edit the action so that Form1.cs looks like this

using System;
using System.Windows.Forms;

namespace ClassLibrary1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ClassLibrary1.WCFServiceLibrary1 client = new ClassLibrary1.WCFServiceLibrary1();
            label1.Text = client.GetData(textBox1.Text);
        }
    }
}

  • 第 7 步 - 添加名为 Program.cs 的 Main 类,内容如下
  • Step 7 - add a Main class called Program.cs with the following content

using System;
using System.Windows.Forms;

namespace ClassLibrary1
{
    public class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 form = new Form1();
            Application.Run(form);
        }
    }
}

  • 第 8 步 - 打开项目属性中的 Application 选项卡(PROJECT >> ClassLibrary1.properties)并设置 Output TypeWindows 应用程序Startup ObjectClassLibrary1.Program

  • Step 8 - Open the Application tab in project properties (PROJECT >> ClassLibrary1.properties) and set Output Type to Windows Application and Startup Object to ClassLibrary1.Program

第 9 步 - F5 将启动表单,其行为将如演练末尾构建客户端应用程序

Step 9 - F5 will launch the form, which will behave as described at the end of the walkthrough under To build a client application

因此,此方法不会执行演练中的测试服务".此外,它还简化了几个步骤,并将 WCF 与 Windows 窗体捆绑在同一个项目中.希望它提供了基本的工作代码,您可以为您的应用程序开发和调整这些代码.

So, what this method does NOT do is go through "Testing the Service" in the walkthrough. Also, it shortcuts a few steps and it bundles the WCF in the same project as the Windows form. Hopefully, it provides bare-bones working code that you can develop and adapt for your application.

这篇关于是否可以使用 Visual Studio Express for Windows Desktop 2013 开始探索 WCF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆