首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有可能开始使用for Windows Desktop 2013来探索WCF?

是否有可能开始使用for Windows Desktop 2013来探索WCF?
EN

Stack Overflow用户
提问于 2014-11-12 12:21:53
回答 1查看 1.4K关注 0票数 1

您能在中为C#设置一个基本的WCF项目吗

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2014-11-13 00:11:01

下面是使用Visual 2013实现http://msdn.microsoft.com/en-us/library/bb386386.aspx的一个可能的解决办法。

所有步骤都是在VSE 2013 for Windows (WDExpress.exe)中执行的。

  • 步骤1-使用Class Library模板启动一个新项目它应该生成一个默认名称为ClassLibrary1的项目
  • 步骤2-转到References (在Solution Explorer中)并添加对System.ServiceModelSystem.Runtime.Serialization的引用
  • 步骤3-创建一个名为WCFServiceLibrary1.cs的新类,其内容如下

代码语言:javascript
复制
using System.ServiceModel;

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

  • 步骤4-创建一个名为IWCFServiceLibrary1.cs的新类,其内容如下

代码语言:javascript
复制
using System.ServiceModel;

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

  • 步骤5-您需要一个客户端来运行WCF,所以创建一个具有默认名称Form1.cs的textBox表单,并添加三个控件:一个textBox,(textBox1),一个标签(label1)和一个按钮(button1)
  • 步骤6-在设计模式中,双击button1并编辑操作,使Form1.cs看起来如下

代码语言:javascript
复制
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的主类,其内容如下

代码语言:javascript
复制
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-在项目属性(PROJECT >> ClassLibrary1.properties)中打开PROJECT >> ClassLibrary1.properties选项卡,并将Output Type设置为Windows Application,将Startup Object设置为ClassLibrary1.Program
  • 步骤9- F5将启动表单,其行为将与在To build a client application下的演练结束时所描述的一样。

因此,此方法不做的是在演练中通过“测试服务”。此外,它还快捷了几个步骤,并将WCF捆绑在与Windows窗体相同的项目中。希望它提供了基本的工作代码,您可以开发和适应您的应用程序。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26886931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档