您能在中为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)复制模板,但没有成功。
发布于 2014-11-13 00:11:01
下面是使用Visual 2013实现http://msdn.microsoft.com/en-us/library/bb386386.aspx的一个可能的解决办法。
所有步骤都是在VSE 2013 for Windows (WDExpress.exe)中执行的。
Class Library模板启动一个新项目它应该生成一个默认名称为ClassLibrary1的项目References (在Solution Explorer中)并添加对System.ServiceModel和System.Runtime.Serialization的引用WCFServiceLibrary1.cs的新类,其内容如下
using System.ServiceModel;
namespace ClassLibrary1
{
public class WCFServiceLibrary1 : IWCFServiceLibrary1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
}
IWCFServiceLibrary1.cs的新类,其内容如下
using System.ServiceModel;
namespace ClassLibrary1
{
[ServiceContract]
public interface IWCFServiceLibrary1
{
[OperationContract]
string GetData(string value);
}
}
Form1.cs的textBox表单,并添加三个控件:一个textBox,(textBox1),一个标签(label1)和一个按钮(button1)button1并编辑操作,使Form1.cs看起来如下
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);
}
}
}
Program.cs的主类,其内容如下
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);
}
}
}
PROJECT >> ClassLibrary1.properties)中打开PROJECT >> ClassLibrary1.properties选项卡,并将Output Type设置为Windows Application,将Startup Object设置为ClassLibrary1.ProgramTo build a client application下的演练结束时所描述的一样。因此,此方法不做的是在演练中通过“测试服务”。此外,它还快捷了几个步骤,并将WCF捆绑在与Windows窗体相同的项目中。希望它提供了基本的工作代码,您可以开发和适应您的应用程序。
https://stackoverflow.com/questions/26886931
复制相似问题